TutorMe Posted December 23, 2007 Share Posted December 23, 2007 I use the following script to create a 401 Unauthorized access page. <?php $user = "bob"; $pass = "bob"; if (!(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $pass)) { header('WWW-Authenticate: Basic Realm="Secured Area"'); header('Status: 401 Unauthorized'); } else { echo "You are in!"; } ?> How would I go about having multiple logins, and being able to add new logins via another script? Edit: I'd eventually like to convert this to work with a mysql database. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted December 23, 2007 Share Posted December 23, 2007 try this <?php $users = array(); $users["bob1"] = "bobpass1"; $users["bob2"] = "bobpass2"; $users["bob3"] = "bobpass3"; $users["bob4"] = "bobpass4"; $valid = false; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { if(array_key_exists($_SERVER['PHP_AUTH_USER'],$users)) { $valid = ($users[$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW']); } } if(!$valid) { header('WWW-Authenticate: Basic Realm="Secured Area"'); header('Status: 401 Unauthorized'); } else { echo "You are in!"; } ?> **untested Quote Link to comment Share on other sites More sharing options...
TutorMe Posted December 23, 2007 Author Share Posted December 23, 2007 Thanks. That worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.