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 ?> |