Please help. I have three PHP pages and I have pasted the following code snippets on each using the “Woody snippets.” plugin. These sessions sometimes communicate within pages based on which page I published last. For example, if I publish page 1 last, I can see the session['rate'] values showing up on page 2 and page 3. But if I publish page 3 last and went into page 1 to populate session[‘rate’] and come back to page 3 again, page 3 will not have this value.
Page 1 code
<?php
session_start();
print_r($_SESSION);
$_SESSION['rate'] = 50;
echo "<br>".$_SESSION['rate']."<br>" ;
?>
Page 2 code
<?php
session_start();
print_r($_SESSION);
echo "<br>".$_SESSION['rate']."<br>";
$_SESSION['rate'] = 10; //This change wont effect on page 1 if I re-visit it.
?>
Page 3 code
<?php
session_start();
print_r($_SESSION);
echo "<br>".$_SESSION['rate']."<br>";
?>
I have installed the “Native PHP Sessions for WordPress” plugin as well, which claims there is an issue with PHP sessions working properly with WordPress. But still no help. You can copy this code and past it into 3 different WordPress pages and you will still see the issue. (session[‘rate’] value is base on which page I publish last. I tried putting session_start(); on the header.php file on the appropriate theme file as well. Still no luck). Placing the following code on the function.php file doesn't help either:
function ses_init() {
if (!session_id())
session_start();
}
add_action('init','ses_init');
Later on, I want a user to stay logged in using sessions. But if sessions are no longer working properly with WordPress, this will not be feasible.