Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 11th, 2004, 10:14 AM
Registered User
Join Date: Jun 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP Sessions

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:


Here's the code that produces the line above from the first page:

session_cache_limiter('private, must re-validate');

(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:


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:

session_cache_limiter('private, must re-validate');
(rest of code here)


  #2 (permalink)  
Old June 11th, 2004, 09:20 PM
Friend of Wrox
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts

I've heard that PHP automatically adds the session id to most links. It's not completely necessary to add it manually, but if you do, try using the function session_id().





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with sessions in php 4.3.11 ocabrera70 Beginning PHP 1 January 31st, 2008 04:28 AM
PHP Sessions - why do I get a warning notice mcmahonc Beginning PHP 0 July 1st, 2007 07:41 AM
How to store check box values in php sessions? method PHP How-To 0 February 22nd, 2006 12:08 AM
How to set up php.ini for sessions club662 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 28th, 2005 12:35 PM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.