C# Programming: HTML login form with PHP processing | Check username and password in php...

Tuesday, June 26, 2018

HTML login form with PHP processing | Check username and password in php...

Html code:

<!DOCTYPE html>

<html>

<head>

<title>Login</title>

</head>

<body>

<form action="logincheck.php" method="post">

  Username:<br>

  <input type="text" name="username" >

  <br>

  Password:<br>

  <input type="password" name="password" >

  <br><br>

  <input type="submit" value="Submit">

</form>
</body>

</html>

Description:

Here in avove html code form tag is used to make form in html such as login or signup form, here i have made a login form. Action is an attribute where we give from which php file our login information will be processed. Here i have logincheck.php file . Method attribute is used to declare whether our form submission method is post method or get method normally we use two methods but there  are other also. Php post method hide the details and get method display in url so for sensitive work like sending password we must use post method.

    Input is used to make typing boxes, we have made two boxes for username and password , type=text means our text is visibke and type =password mean our text is hidden and shown in bullet form.

At last input type=submit means we have created a button upon clicking of it our login info is sent to the provided action file here is logincheck.php.



PHP code:

<?php

$username=$_POST['username'];

$password=$_POST['password'];

if($username == "username" && $password=="password")

{
echo "You are successfully logged in";
}

else

{

echo "Sorry username or password is wrong.";

}

?>

Description:

Here two variables are used to store values passed from html form for username and password $_POST is used for such task. By using if condition we check whether given username and password are correct or not here we have hard coded value for username and password as "username" and "password"  respectively.If there correct info echo will display success message else not. echo is used to print any text.





This video demonstrates how we can make login form and process it with php. Post method is used to submit login form data to the php action file.

No comments:

Post a Comment