PHP Session Variable to WordPress Error

Question

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()) {
    session_start();
}
}

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

if (!session_id())
session_start();

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');
session_write_close();

The next page is:

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

‘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.

0
, Maxwell 7 months 0 Answers 103 views 0

Leave an answer