Forum Moderators: coopster

Message Too Old, No Replies

Session Checking Issue.

Displaying the wrong links until they're clicked.

         

Tom_Cash

5:34 pm on Feb 10, 2009 (gmt 0)

10+ Year Member



Hi folks,
this is a arkward one to explain. Basically, on my site, you can log in. Once you're logged in, a login session is set and various links change.

For example, 'log in' becomes 'log out' and 'register' becomes 'my account'.

You can only see these links when logged in.

However, if you were to leave the page without leaving the browser and come back later, it treats you as if you are not logged in. If you refresh the page, nothing changes.

However, when you click the log in link, my pre-programmed error kicks in and tells me I am already logged in. It's not until this point, the header links change.

Here's my code, should it help:

// HEADER.PHP

if (isset($_SESSION['login']) == 1)
{
log out, home.
}

else
{
log in, register.
}

// LOG_IN.PHP

if (isset($_SESSION['login']) == 1)
{
general error.
}

Any help would be ace,
Cheers,
Tom.

Tom_Cash

1:49 am on Feb 12, 2009 (gmt 0)

10+ Year Member



Just to add...

I changed my header to code to read:

// HEADER.PHP

if (isset($_SESSION['login']) > 0)
{
log out, home.
}

else
{
log in, register.
}

And it worked for a while - then stopped.

Please, ideas, anyone?

Cheers,
Tom.

rob7591

2:14 am on Feb 12, 2009 (gmt 0)

10+ Year Member



What's stored in $_SESSION['login']? is it the username or just a 1 or 0,

using isset just checks if there's anything in $_SESSION['login'] so you can have $_SESSION['login'] = 0 and isset will still return 1.

If $_SESSION['login'] is always 1 or 0, I would make your if statement look like this:

if ($_SESSION['login'] > 0) {
log out,
} else {
etc.
}

Tom_Cash

11:34 am on Feb 12, 2009 (gmt 0)

10+ Year Member



Hi Rob, thanks for the reply.

I just store a 1 or 0, but I did try what you said (my second post in this thread) and it didn't work... Well, it just stopped, for some odd reason. It's quite frustrating.

Is there anything that could be interfering with it?

Tom_Cash

3:38 pm on Feb 14, 2009 (gmt 0)

10+ Year Member



Bump... Help... Please.

rob7591

4:33 pm on Feb 14, 2009 (gmt 0)

10+ Year Member



In your second post, you still have:

if ( isset($_SESSION['login']) > 0 )

isset will still return true if $_SESSION['login'] = 0

Take out the isset() and it should work.

Tom_Cash

12:33 am on Feb 16, 2009 (gmt 0)

10+ Year Member



Hi Rob, thanks for another reply.

I did remove the isset, but to no avail. :( Any other ideas?

stargateanubis14

1:45 am on Feb 16, 2009 (gmt 0)

10+ Year Member



i may not get what your tryin to do, but would it be easy to:

// HEADER.PHP
)if (isset($_SESSION['login'])
{
if ($_SESSION['login']) == 1) //if user is logged in
{
log out, home.
}
else
if ($_SESSION['login']) == 0)
{
log in, register.
}
}
else
{
log in, register.
}

// LOG_IN.PHP
if isset($_SESSION['login'])
{
if ($_SESSION['login']) == 1)
{
general error.
}
}