Snippet: Are sessions working?

Posted on October 16, 2007
Filed Under Code Snippets |

Description:

You can use this piece of code to check if it is possible to use sessions for the visitor.

This can come handy for login pages. If you have cookies disabled and try to login, no login session can be used. In such cases it is nice to inform your visitors.

Code:
PHP:



<?php

session_start ();
//Check GET request
if (isset ($_GET[‘cookie_check’])){
//Check session
if (isset ($_SESSION[’session_set’])){
//Display working message
echo “working…”;
exit;
//Or redirect
//header (”Location: cookie_working.php”);
} else {
//Display failure message
echo “failure…”;
exit;
//Or redirect
//header (”Location: cookie_fail.php”);
}
}
session_register (“session_set”);
$_SESSION[’session_set’] = true;
header (“Location: cookie_check.php?cookie_check=1″);

?>

Comments

Your Ad Here

Leave a Reply