Jump to content

Help With Sessions


steviez

Recommended Posts

Hi,

 

I am having some strange problems with sessions in my script.

 

When a user logs in my script sets the sessions as follows:

 

session_start();
$_SESSION['loggedin'] = 1;

 

And then on member only pages i use this code to check if they are logged in:

 

session_start();
if(!isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == md5("TRUE"))
    {
    header("location: $secure_url/login.php");
    exit();
    }

 

But it always redirects the users to the login page, but if i echo the session i get the value.

 

Any ideas?

 

Thanks

But

Link to comment
Share on other sites

link=topic=192273.msg863757#msg863757 date=1208036971]

have you also troubleshooted the $_SESSIONs? just trying to echoing out the value of them and see if it's printing out the expected result?

 

I have done that and i am getting the exact result that i want. Its only when i try to check if its set.

Link to comment
Share on other sites

pretty sure you would have to use the $_SESSION['loggedin']

 

and maybe try...

 

<?php

session_start();
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1)
{
  // ok
}
else
{
  header("location: $secure_url/login.php");
  exit();
}

?>

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.