PHP Sessions
Hi,
Have built a shopping cart system and have tested it on Netscape, AOL, IE5 & IE6 with cookies enabled and disabled and everything seems to work ok. Using PHP 4.3.3 and MySQL. Although everything seems to work ok for me, one unusual thing happens that I can't figure out.
On the first page, where products are displayed, PHPSESSID appears twice like this:
...PHPSESSID=&PHPSESSID=f345599fker(etc.)
Here's the code that produces the line above from the first page:
<?php
session_cache_limiter('private, must re-validate');
session_start();
?>
<?
(code to get data from database to display individual products here)
// link to detailed product description
<a href="product_detail.php?product_id=<? echo $product_id; ?>&PHPSESSID=<? echo $PHPSESSID; ?>"><? echo $product_title; ?></a>
Again, I get the following result on the page:
...PHPSESSID=&PHPSESSID=f345599fker(etc.)
As I go from page to page, this ...PHPSESSID=&PHPSESSID=f345599fker(etc.) eventually disappears (after going to about 3 or 4 pages) and then only &PHPSESSID=f345599fker(etc.) appears. On all other
pages, other than the first page, I use the following convention for links:
<a href="page_name.php?PHPSESSID=<? echo $PHPSESSID; ?>
The following line gives the same effect when it is on the first page; i.e., creates ...PHPSESSID=&PHPSESSID=f345599fker(etc.):
<a href="product_detail.php?PHPSESSID=<? echo $PHPSESSID; ?>&product_id=<? echo $product_id; ?>"><? echo $product_title; ?></a>
Lastly, the line below properly creates (on the first page) only one PHPSESSID=
<a href="product_detail.php?product_id=<? echo $product_id; ?>"><? echo $product_title; ?></a>
when it appears on the first page. Linking to subsequent pages retains only one PHPSESSID= throughout.
I was wondering if someone had an explanation as to why
Just to be complete, the following code appears at the top of each page, other than the first page:
<?php
session_cache_limiter('private, must re-validate');
if(!$PHPSESSID){
session_start();
}
?>
<?
(rest of code here)
Thanks
|