Skip to content

Instantly share code, notes, and snippets.

@lukas-buergi
Created June 26, 2012 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save lukas-buergi/2995743 to your computer and use it in GitHub Desktop.
Save lukas-buergi/2995743 to your computer and use it in GitHub Desktop.
Check whether sessions work in php
<?php
error_reporting( E_ALL );
ini_set( 'display_errors', 1);
if(!isset($_GET['action'])){
die('Param is missing. Look at the <a href="https://gist.github.com/2995743">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>';
}else{
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 'session.name : ' . ini_get('session.name') . '</br>';
break;
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'] );
}
session_destroy();
echo "Test session deleted.";
break;
case "check":
session_start();
if(isset($_SESSION['test']) and $_SESSION['test'] == 'test'){
echo "Sessions seem to work. :-)";
}else{
echo "Sessions don't seem to work. :-(";
}
break;
default: die("Hey, I told you to look at the source, idiot. :P");
}
?>
@matthewmalk248
Copy link

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

and it will work :)

@kimboslice99
Copy link

@matthewmalk248, I think you meant if(isset($_SESSION['test']) and $_SESSION['test'] == 'test123'){

@lukas-buergi
Copy link
Author

Just for the record, I think it's highly amusing that some people are using this buggy snippet that I think I wrote when I was in middle school. @matthewmalk248
Do so at your own risk.

@kimboslice99
Copy link

Nothing wrong with a nice simple script to copy paste and check session functionality on a fresh setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment