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. Link to comment https://forums.phpfreaks.com/topic/82866-solved-401-with-multiple-logins/ 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 Link to comment https://forums.phpfreaks.com/topic/82866-solved-401-with-multiple-logins/#findComment-421465 Share on other sites More sharing options...
TutorMe Posted December 23, 2007 Author Share Posted December 23, 2007 Thanks. That worked. Link to comment https://forums.phpfreaks.com/topic/82866-solved-401-with-multiple-logins/#findComment-421828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.