PHP User Login Code

Source: Internet
Author: User

Method one window to authenticate user login


The code is as follows Copy Code

$admin _name= "admin";
$admin _pawd= "admin";
if ($php _auth_user!= $admin _name| | $php _auth_pw!= $admin _pawd)
{
Header (' Www-authenticate:basic realm= "System verification");
Header (' http/1.0 401 Unauthorized ');
echo "Server rejects request, you do not have permission!";
Exit ();
}

//


if (Empty ($_server[' Php_auth_user ')) {
Header ("content-type:text/html; Charset=big5 ");
Header (' Www-authenticate:basic realm= "Authentication");
Header (' http/1.0 401 Unauthorized ');
Echo ' Please enter the correct account number and password, can not be canceled! '
Exit
} else {
echo "Your login account is". $_server[' Php_auth_user '. " <br> ";
echo "The password you use is". $_server[' PHP_AUTH_PW '. " <p> ";
$correctname = "John";
$CORRECTPWD = "1234";
if (($_server[' php_auth_user ']!= $correctname) or
($_server[' PHP_AUTH_PW ']!= $correctpwd)) {
echo "Login failed, please open a new browser to log in again";
}else{
echo "Login succeeded ...";
}
}
?>

Method two PHP mysq

The code is as follows Copy Code

<?php
if (($_post[' name ']!= "John") or ($_post[' passwd ']!= "1234")):
?>
<title> Login Screen </title>
<body>
<b> did not enter account number or password, or account number, incorrect password </b><p>
<form action=<?php echo $_server[' php_self ']?> method=post>
Account <input type=text name=name value= "Please enter account" size=10><p>
Password <input type=password name=passwd size=10><p>
<input type=submit value= "Login" >
<input type=reset value= "Clear" >
</form>
</body>
<?php
Else
echo "Login successful .....<p>";
echo "Your login account is". $_post[' name '. " <br> ";
echo "The password you use is". $_post[' passwd '];
endif
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.