Forked from strangerstudios/init_session_var_test.php
Last active
April 21, 2020 08:07
-
-
Save andrewlimaza/58c1e5546f3f682a0448401009c71659 to your computer and use it in GitHub Desktop.
Testing if $_SESSION variables work in WordPress/PHP. Test session
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