Jump to content

Require password but not if from certain link


SEVIZ

Recommended Posts

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.

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

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.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.