SEVIZ Posted June 16, 2009 Share Posted June 16, 2009 I am using this simple code for a password protect on a php page. <?php // If password is valid let the user get access if (isset($_POST["password"]) && ($_POST["password"]=="$password")) { ?> After the above it displays the content or a login depending on if they entered the password. How can I edit the if statement to also allowed access if the user is coming from a certain address? The reason is that this password gains access to a form that on submit goes to a second page that actually does the query and such. Once done that page redirects back to the form. Currently it then asks for the password again. I want it to just display the content since they are coming from that link. Thanks for any ideas. Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/ Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 Rather than checking the referring URL, you should just use a session variable (its like a cookie) that says the user is logged in. Then check to see if that variable is set before you request a password. Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-856749 Share on other sites More sharing options...
SEVIZ Posted June 16, 2009 Author Share Posted June 16, 2009 Any links to how sessions work? I am extremely new to this and have no knowledge of these. Thanks for any tips! Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-856755 Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 There are about 103845 tutorials out there on sessions. Pick any of them, they aren't a hard concept, and looking at two or three tutorials should be enough for you to get the hang of it. Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-856764 Share on other sites More sharing options...
SEVIZ Posted June 16, 2009 Author Share Posted June 16, 2009 Your post in my other thread helped already. Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-856768 Share on other sites More sharing options...
SEVIZ Posted June 16, 2009 Author Share Posted June 16, 2009 Ok I am using this code <?php // If password is valid let the user get access if (isset($_POST["password"]) && ($_POST["password"]=="$password") || ($_SESSION['login'])) { ?> The above says if the password is right or session login is there let them in. But where do I start the session login? It seems like I should start it in the same place since the session should be started when they are logged in. Any help is appreciated Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-856786 Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 You can break it into two: session_start() if(!isset($_SESSION['login']) || !$_SESSION['login']) { if(isset($_POST['password']) && $_POST['password'] == "$password") { $_SESSION['login'] == TRUE; } } if(isset($_SESSION['login'] && $_SESSION['login'])) { // do the logged in stuff } else { // dont. } Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-856803 Share on other sites More sharing options...
SEVIZ Posted June 17, 2009 Author Share Posted June 17, 2009 EDIT Link to comment https://forums.phpfreaks.com/topic/162323-require-password-but-not-if-from-certain-link/#findComment-857653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.