0

I've just encountered a problem. I store session ids in a cookie to retrieve the basket info when a user leaves a site and then comes back again. My problem being that as a test i cleared all sessions but kept the cookie but now the page just continues to load.

my question is, is there a way to firstly use php to get the tmp directory for me to then test if the session id stored is valid.

regards,

Phil

EDIT

i currently use

if( isset( $_COOKIE[$cookieKey] ) ) {
    session_id( $_COOKIE[$cookieKey] );
}
// create a new or carry on the existing session
session_start();

which is giving me the problem

Phil Jackson
  • 10,238
  • 23
  • 96
  • 130

1 Answers1

1

That's unreliable and unnecessary. Instead, add checks in your code to find out whether the $_SESSION superglobal is empty or (even better) has the appropriate keys:

<?php
if( !isset($_SESSION['foo']) ){
    // User is not fooed yet
    $_SESSION['foo'] = 33;
}
find_records_by_foo($_SESSION['foo']);

Update: No matter what you want to do with cookies and session IDs, my answer still applies. Once you're done with your cookie checks, make you session tests with isset().

Álvaro González
  • 142,137
  • 41
  • 261
  • 360