Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Check whether sessions work in php
error_reporting( E_ALL );
ini_set( 'display_errors', 1);
die('Param is missing. Look at the <a href="">source</a>.');
switch($_GET['action']) {
case "start":
if(session_start() && $_SESSION['test']='test123'){
echo 'Test session probably started successfully. Go <a href="mySessionTest.php?action=check">check</a>!</br>';
echo 'Starting a test session seems to have failed. Go <a href="mySessionTest.php?action=check">check</a>!</br>';
echo 'And some additional information:</br>';
echo 'session.save_path : ' . ini_get('session.save_path') . '</br>';
echo 'session.cookie_path : ' . ini_get('session.cookie_path') . '</br>';
echo ' : ' . ini_get('') . '</br>';
case "delete":
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly'] );
echo "Test session deleted.";
case "check":
if(isset($_SESSION['test']) and $_SESSION['test'] == 'test'){
echo "Sessions seem to work. :-)";
echo "Sessions don't seem to work. :-(";
default: die("Hey, I told you to look at the source, idiot. :P");

This comment has been minimized.

Copy link

commented Feb 12, 2019

Change line 33 to if(isset($_SESSION['test']) and $_SESSION['test123'] == 'test'){

and it will work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.