user authentication

 <?php
session_start();
$vu = array('user1' => 'password1', 'user2' => 'password2');

function doAuth() {
    header('WWW-Authenticate: Basic realm="User Authentication"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'You cannot view this page.';
    exit;    
}

function checkUser() {
    global $vu;
    $b = false;
    if($_SERVER['PHP_AUTH_USER']!='' && $_SERVER['PHP_AUTH_PW']!='') {
        if($vu[$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW']) $b = true;
    }
    return $b;
}

if(!checkUser()) doAuth();

// The rest of the page
?> 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*