I am having some strange problems with SESSION variables in my shopping cart in PHP / Ajax.
When I first view the page, SESSION is created and works inside the page. Then, when I go to another PHP page in the same directory, SESSION is completely lost. What is strange is that this happens only once . When the user goes through this process, completely losing their SESSION when changing the page, SESSION works completely throughout the cart.
I started sending my var_exports both $ _SESSION and $ _SERVER data on every pageview. It seems that when the page is first viewed, there is a SESSION and contains data. However, there is no PHPSESSID generated in the variable $ _SERVER ['HTTP_COOKIE']. When you go to another page, PHPSESSID is created, and SESSION will start working, but the original SESSION data for the first page view will be lost.
Is there a way to create a PHPSESSID if it has not already been created for the SESSION? Or is this typical behavior and is not relevant to my random SESSION loss problem? I am using PHP 5.2.
Each page in the basket begins exactly the same:
$title="Title"; $keywords="keywords"; $description="description"; @include('../header_cart.php');
And then at the top of header_cart.php is:
session_start(); if(!isset($_SESSION['active'])){ $_SESSION['active']=$_SERVER['REMOTE_ADDR']; }
unsunghero
source share