Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active June 26, 2018 20:20
Show Gist options
  • Save ideadude/93f06c4c7b3f9f1a7bbce27473304b8d to your computer and use it in GitHub Desktop.
Save ideadude/93f06c4c7b3f9f1a7bbce27473304b8d to your computer and use it in GitHub Desktop.
Test if PHP Session Variables are working.
<?php
/**
* Test if PHP Session Variables are working.
* Step 1: Add this code into a custom plugin or in a PHP file you know is being executed.
* Step 2: Navigate to /?test=123. You should see a blank old value and 123 as the new value.
* Step 3: Navigate to /?test=456. You should see 123 as the old value and 456 as the new value.
* If you see a blank old value again, that means that session variables are not enabled or otherwise broken.
* If the timestamp at the top is not being updated, the page may be cached.
* Step 4: Remove this code.
*/
if(!empty($_REQUEST['test'])) {
session_start();
echo date('y-m-d h:i:s') . '<br />';
echo 'Old value: ' . $_SESSION['test'] . '<br />';
$_SESSION['test'] = $_REQUEST['test'];
echo 'New Value: ' . $_SESSION['test'] . '<br />';
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment