PHP Session Variable to WordPress Error


I have been trying to figure out how to add session variables to WordPress Custom Pages for the past few days but have still been unable to find a solution. From researching it seems WordPress does not allow you to move Session variables from one page to the next. I have tried removing all of the ‘session_start();’ from each page and adding the below to functions.php file.

add_action('init', 'myStartSession', 1);
function myStartSession() {
if(!session_id()) {

Have also tried adding code below to the wp-config.php but to no avail.

if (!session_id())

The session will create a unique id for each user which will be checked on the next page to see if it equals the previous id. The first page code is as follows:

$_SESSION['t'] = md5(session_id().'3ac49262e797b6a51b6362e264d9dbe1');

The next page is:

$testValue = md5(session_id().'3ac49262e797b6a51b6362e264d9dbe1');
if ($testValue == $_SESSION['t'])
{$passFlag = 1;}
{$passFlag = 0;}

‘session_write_close();’ is called further down on this page.
Any help would be greatly appreciated and if you need any further information please don’t hesitate to message. Thanks.

, Maxwell 7 months 0 Answers 103 views 0

Leave an answer