php - check to see if a session file exists on server
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 sessi开发者_JS百科on 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
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()
.
精彩评论