Categories
CMS Mastering Development Wordpress

php session not going to next page in wordpress

I have a WordPress website. As the sessions are not activated by default I did the following code in my function.php:

function ur_theme_start_session()
{
if (!session_id())
    session_start();
}
add_action("init", "ur_theme_start_session", 1);

Now I am getting value from URL and storing it in session like below:

$_SESSION['accessory'] = $_GET['item'];
$accessory=$_SESSION['accessory'];

The sessions variable is only echoing in the same page where the variable is retrieved; when I go to other pages the values is not stored. How can I fix it?

Leave a Reply

Your email address will not be published. Required fields are marked *