The Wicked Coder

PHP, fun and all

Simple Password protection using PHP

Utilize this straightforward script to secret word secure your pages, Ideal for watchword ensuring Administrative parts or delicate parts of your site.

The rationale behind the script is extremely basic at whatever point your secret key secured page is known as the script is initially called it checks for the username and watchword if not discovered, presents you with a login page and when you submit insight (username, secret key) it checks if the information is right if right permits you to get to the ensured page, else denies access.

Don’t get perplexed by the measure of the PHP script, its is truly basic it basically looks huge coz, to bring about a noticeable improvement I had included a great deal of HTML tags and tables. I have utilized this same script with a little variety (included database help) in numerous commerical provisions 😉


Installation: To protect a particular page use the include directive to include this script in your page. 

Example: <?php include ‘password_protect_page.php’; ?> 

DEMO: Click here to see a demo of this script. 
Username: admin 
Password: pass 


[prettify class=”php”]



: Authentication Required



(Access Restricted to Authorized Personnel)





User Name







else {

function login_error($host,$php_self) {

echo ”

$host : Administration


You Need to log on to access this part of the site!




echo “Error: You are not authorized to access this part of the site!

Click here to login again.









$user_checked_passed = false;

if(isset($HTTP_SESSION_VARS[‘adb_password’])) {

$adb_session_password = $HTTP_SESSION_VARS[‘adb_password’];

$adb_session_user = $HTTP_SESSION_VARS[‘user’];

if($admin_password != $adb_session_password)


else {

$user_checked_passed = true;



if($user_checked_passed == false) {

if(strlen($u_name)< 2) login_error($HTTP_SERVER_VARS[‘HTTP_HOST’],$HTTP_SERVER_VARS[‘PHP_SELF’]); if(isset($admin_password)) { if($admin_password == $u_password) { session_register(“adb_password”); session_register(“user”); $adb_password = $admin_password; $user = $u_name; } else { //password in-correct login_error($HTTP_SERVER_VARS[‘HTTP_HOST’],$HTTP_SERVER_VARS[‘PHP_SELF’]); } } else { login_error($HTTP_SERVER_VARS[‘HTTP_HOST’],$HTTP_SERVER_VARS[‘PHP_SELF’]); } $page_location = $HTTP_SERVER_VARS[‘PHP_SELF’]; if(isset($HTTP_SERVER_VARS[“QUERY_STRING”])) $page_location = $page_location .”?”. $HTTP_SERVER_VARS[“QUERY_STRING”]; header (“Location: “. $page_location); } } } ?>[/prettify]



Updated: April 21, 2014 — 6:58 pm
The Wicked Coder © 2014