Sometimes you might wish to make certain pages of your site just perceptible to a chosen few. you can do this by utilizing Phps constructed within Http Authentication. The code ought to go right at the highest point of your php page so don’t get ‘headers Already Sent’ mistakes. You can see that we’ve specified the username and secret word in the variables at the highest point of the script you can change these to reflect your own particular username and watchword.
You could effortlessly make this verification more dynamic by checking a database for the username and watchword. We can get whatever the client sorted into the dropdown box by tagging the accompanying superglobals.
//Username:
<?php echo $_SERVER[‘PHP_AUTH_USER’];?>
//Password:
<?php echo $_SERVER[‘PHP_AUTH_PW’];?>
The Code
<?php
$config[‘admin_username’] = “demo”;
$config[‘admin_password’] = “demo”;
if (!($_SERVER[‘PHP_AUTH_USER’] == $config[‘admin_username’] && $_SERVER[‘PHP_AUTH_PW’] == $config[‘admin_password’])) {
header(“WWW-Authenticate: Basic realm=”Papermashup.com Demo Admin””);
header(“HTTP/1.0 401 Unauthorized”);
echo ‘This is what happens if you press cancel’;
?>
<?php
exit;
}
// if the username and password match show the rest of the content
?>
Thanks for publicing this awesome information. Keep up the great job. I’ll subscribe to your site also. Thnx!
What’s up all, here every person is sharing such experience, therefore it’s nice to read this weblog, and I used to visit this website everyday.