PHP Code for login authentication using File data.

PHP Code:

<!DOCTYPE html>
<html>
    <head>
        <style>
            input{
                width: 200px;
                font-size: 20px;
                padding: 10px;
                margin: 10px;
            }
        </style>
    </head>
<body>

<h3>Php Code for login authentication using File data</h2>

<form method="POST">
    <h2>Ragister</h2>
    <input type="text" name="uname" placeholder="Enter Username.." required />
    <input type="password" name="pass" placeholder="Enter password.." required />
    <input type="submit" value="sign up" name="signup">
    <input type="submit" value="sign in" id="in" name="signin">
</form>

<?php
    if (isset($_POST['signup'])){
        $myfile = fopen("program5.txt", "w");
        $userdata = $_POST['uname']." ".$_POST['pass'];
        fwrite($myfile, $userdata);
        fclose($myfile);
    }
    if (isset($_POST['signin'])){
        $outfile = fopen("program5.txt", "r") or die("Unable to open file!");
        $inuser = $_POST['uname'];
        $inpass = $_POST['pass'];
        $data = fread($outfile,filesize("program5.txt"));
        $result = explode(' ', $data);
        if($inuser == $result[0] && $inpass == $result[1]){
            echo "Login successfull";
        }
        else{
            echo "Wrong username or password";
        }
        fclose($outfile);
    }
?>

</body>
</html>

Output:

Comments

Popular posts from this blog

PHP Code to print first 10 Fibonacci Numbers

Create a simple HTML page to demonstrate the use of different tags

Use Tables to provide layout to your web page.