// Check Username and password correct or ask for them
if(($_SERVER['PHP_AUTH_USER'] == "myusername") AND
($_SERVER['PHP_AUTH_PW'] == "mypassword"))
{ ?>
Protected Content Here
<?php } else {
// Ask for username and password
header("WWW-Authenticate: " ."Basic realm=\"Ojambo.com's Protected Area\"");
header("HTTP/1.0 401 Unauthorized");
// Show failure text after several failed attempts
echo "This area is protected by a valid username and password";
}
?>
Have htaccess style password protection using PHP
3 Responses
What its doing is checking to make sure you have logged in via your Cpanel and if you are you will see the protected content, if not it will redirect you to the login page if you fail to login it will display "This area is protected by a valid username and password"
then it will redirect you to a 401 page saying your Unauthorized to view the page
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.