Jump to content

why does this work


Reaper0167

Recommended Posts

first off,,, sorry about all the questions... but in my login script i have

<?php
if($count==1)
{
session_start();
$_SESSION['auth'] = "yes";
$message = "Welcome $username. You are now logged in.";
header("location: home.php?error=" . urlencode($message));
}
?>

and on my members page i have this

<?php
session_start();
//Checking if user is logged in. If not, re-direct them to login form.
if (!isset($_SESSION['auth']))
{
header("Location: index.php");
}
?>

 

I did accomplish what i was trying to do. I wanted only a logged in user to be able to access my members page. If your logged in and and type the address in you can access the page. But if you close your browser and type in the address it takes you directly back to the login/register page... Which is great. Works perfect for me...Here is my question,,,,, i am setting my session auth to yes... so how is the !isset working with session auth set to yes... Basically could someone explain how the !isset is talking to the session being set to yes.....  The way i see it,,, i would do something like this...

if $_SESSION['auth'] != "yes"

{

      header ("Location: index.php");

}

 

How does that !isset work with a yes and a no like i have here????

Hopefully someone understands.

Link to comment
Share on other sites

isset checks if there's anything in this variable. So even if you set $_SESSION['auth'] to "no", "123", 123, 3.14 or whatever you wish, it will return true. It will return false if and only if, the variable is not set (note, that empty variable and not set variable are not same thing).
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.