moechyman Posted April 11, 2009 Share Posted April 11, 2009 I have used the code below to try and password protect a website, but I can't get it to work. Where did I go wrong? <?php $login_successful==true; // check user & pwd: if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){ $usr == $_SERVER['PHP_AUTH_USER']; $pwd == $_SERVER['PHP_AUTH_PW']; if ($usr == ' ' && $pwd == 'murphy'){ } } // login ok? $login_successful==false; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){ if ($usr != ' ' && $pwd != 'murphy'){ //send 401 headers: //realm="something"; header('WWW-Authenticate: Basic realm=Sorry please try again'); header('HTTP/1.0 401 Unauthorized'); print("Login failed!"); } } ?> Link to comment https://forums.phpfreaks.com/topic/153644-authphp-password-protected-website/ Share on other sites More sharing options...
9three Posted April 11, 2009 Share Posted April 11, 2009 You have a misunderstanding of using the single equals and double equals. Furthermore, your logic is flawed. 1 equal - Assigns variables $assign1 = $_POST['username']; $assign2 = 'Hello'; //Prints a username grabbed from another page echo $assign1; //Prints hello echo $assign2; 2 equals - Checks to see if the variable matches $user1 = 'Ben'; $user2 = 'Fin' $user3 = 'Ben'; //Will echo They dont match! if ($user1 == $user2) echo 'They match!'; else echo 'They dont match!'; //Will echo They match! if ($user1 == $user3) echo 'They match!'; else echo 'They dont match!'; Link to comment https://forums.phpfreaks.com/topic/153644-authphp-password-protected-website/#findComment-807365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.