php http authentication example
php http authentication example |
These components are altogether based around the utilization of the 401 status code and the WWW-Authenticate reaction header.
HTTP Authentication is best way to Restrict user to access personal or protected area of your website..
HTTP Authentication is also called basic login..
just use the below codes to create simple HTTP Authentication
authentication.php
<?php $authenticate = false; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $name = $_SERVER['PHP_AUTH_USER']; $pass = $_SERVER['PHP_AUTH_PW']; if ($name == 'admin' && $pass == 'admin') { $authenticate = true; } } if ($authenticate==false) { header('WWW-Authenticate: Basic realm="Restricted Page please login To Continue"'); header('HTTP/1.0 401 Unauthorized'); echo "Login Failed Please Refresh To Login Again"; } else { ?> <html> <head> <title>PHP HTTP Authentication to Secure your Website--CodeNair</title> </head> <body> <h1>Simple PHP HTTP Authentication to Secure your Website--CodeNair</h1> <p>Welcome to CodeNair ..You can not see this content until you logged in...</p> </body> </html> <?php } ?>
N.B: Your Username and Password is admin
that's it friends how to create http authentication with php..please share with your friends ..Thank You..
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.