Created
March 27, 2015 16:14
-
-
Save strangerstudios/d2715d860dc483466076 to your computer and use it in GitHub Desktop.
Testing if $_SESSION variables work in WordPress/PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function init_session_var_test() | |
{ | |
//must set /?sessiontest=SOMETHING to get this to run | |
if(empty($_REQUEST['sessiontest'])) | |
return; | |
//start session | |
if (version_compare(phpversion(), '5.4.0', '>=')) { | |
if (session_status() == PHP_SESSION_NONE) | |
session_start(); | |
} | |
else { | |
if(!session_id()) | |
session_start(); | |
} | |
//show old value | |
echo "Old value: " . $_SESSION['sessiontest'] . "<br />"; | |
//set from REQUEST | |
$_SESSION['sessiontest'] = $_REQUEST['sessiontest']; | |
//show new value | |
echo "New value: " . $_SESSION['sessiontest'] . "<br />"; | |
exit; | |
} | |
add_action('init', 'init_session_var_test'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment