Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

Protect page using password in PHP

Sun Nov 30, 2008 8:44 pm

Using this code you can protect a single page .users have to enter password to view the page .The code check if correct password and username .


Code:

<?php

function checklogin($username, $password){
    if (
            (
                !isset(
$_SERVER['USER_USERNAME']) ||
                (
                    isset(
$_SERVER['USER_USERNAME']) &&
                    
$_SERVER['USER_USERNAME'] != $username
                
)
            ) &&
            (
                !isset(
$_SERVER['USER_PASSWORD']) ||
                (
                    isset(
$_SERVER['USER_PASSWORD']) &&
                    
$_SERVER['USER_PASSWORD'] != $password
                
)
            )
        )
    {
        
header('WWW-Authenticate: Basic realm="Login"');
        
header('HTTP/1.0 401 Unauthorized');
        echo
'Please login first.';
        exit;
    }
}
?>




Post a reply
  Related Posts  to : Protect page using password in PHP
 php Password protect a page     -  
 How to protect your software     -  
 Image Scroller-scrollbar-LINE_UP,LINE_DOWN-PAGE-UP-PAGE-DOWN     -  
 how to encrypt password in jsp     -  
 generate password using php     -  
 simple password Strength checker     -  
 Input username and password in JAVA     -  
 Password Security Manager Access File Java     -  
 AJAX Login Code getting username and password dynamically .     -  
 Mile200: Removing Username, Password & Login from Header     -  

Topic Tags

PHP Validation