Jump to content
xisto Community

Http Authentication

Recommended Posts

I have a book called PHP and MySQL for dynamic web sites by Larry Ullman, and it's a very good book which I would recomend to anyone wanting to learn, but I followed a project in this book, not letter by letter, and it won' work.
I wrote this code to create an authentication script that will only work with one user but allow the credientals to be passed from one page to another. So here's the code

<?PHP$aut = FALSE;  //Check for user variablesif ( (isset($_server['PHP_AUTH_USER']) AND isset($_server['PHP_AUTH_PW'])) ) {  //Check for correct user and password  $user = $_server['PHP_AUTH_USER'];  $pw = $_server['PHP_AUTH_PW'];    if ($user == "user" AND $pw == "password"){    $aut = TRUE;  }}//IF not authorized ask for authenticationif ($aut == FALSE){  header('WWW-Authenticate: Basic realm="d-gression HTML editor"');  header('HTTP/1.0 401 Unauthorized'); //If cancel is pressed}?>
and the actual page the require points to the above code
<?PHPrequire('./auth.inc');if ($aut == FALSE){  echo "please <a href=\"index.php\">try again.</a>";} else {  echo "you're in!!!";}?>

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.