Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Forked from ideadude/test_php_session_vars.php
Last active June 21, 2018 16:19
Show Gist options
  • Save pbrocks/66f36441239bfd3a4cd3b7a67dba111e to your computer and use it in GitHub Desktop.
Save pbrocks/66f36441239bfd3a4cd3b7a67dba111e to your computer and use it in GitHub Desktop.
Test if PHP Session Variables are working.
<?php
session_start();
/**
* 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'] ) ) {
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