I'm working through a book which creates this function for destroying a session:
function destroy_session_and_data()
{
session_start();
$_SESSION = array();
if (session_id() != "" || isset($_COOKIE[session_name()]))
setcookie(session_name(), '', time() - 2592000, '/');
session_destroy();
}
I was wondering whether the conditional statement is overly long?
Could it not be rewritten as the following:
if (session_id() != "" || isset(session_name()))
That is, doesn't session_name() return the value 'PHPSESSID' without the need for a specific reference to the $_COOKIE array?
Going further, could the conditional not just be written like this:
if (session_id() != "")
Seeing as session_id() returns the VALUE of the key [PHPSESSID] in the $_COOKIE array, if it is not empty then surely it goes without saying that session_name(), which returns the KEY [PHPSESSID], will be set, because they exist together as a name/value pair in the $_COOKIE array?
Cheers for any help!