Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Problem

Status
Not open for further replies.

Dynamo3209

Programmer
Joined
Jan 2, 2003
Messages
57
Location
US
Hi,
I have designed a shopping cart. However I am getting some error working with session.
The problem is when I run the shopping cart application it runs fine, but when I close the browser and again reopen the browser and run the application, in my checkout it shows me null session. However if I delete all cookies, history and tmp files and then rerun the application it again sets tne session and everything goes well.
I am not sure where the problem is.
Appreciate any comments on this.
Thanks,
Dynamo
 
I'm not clear on the issue... is the below accurate?

So closing/reopening the browser empties the session, but you're still looking for it. Erasing all cookies/history/temp files empties the session and makes it so you're no longer looking for it?

If so, it sounds like you have some faulty logic as to when to look for a session which is based on a cookie.

Without knowing more about your code/webserver installation/browser it's really hard to say.
 
No if all the cookies/history/temp files are deleted and the application is run again from the beginning (choosing the items to purchase and then moving forward till the checkout) everything works fine all the items purchased are shown at the checkout and those items can be purchased.
However if I open a new instance of the browser and do not delete cookies/history/tmp files and rerun the application it shows be null session at the checkout page.
Whenever the browser is closed or the checkout is complete I am destroying all the cookies and the session. So on re-starting the browser it should work fine, however it shows me a null session.
Using PHP, MySql, Apache.

Thanks
 
What version of PHP? How are you instantiating your session variables? How are you testing for the presence of session variables?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Using php 4.
Code:
session_register ("ASTROLOGY_session");

foreach($HTTP_POST_VARS as  $key=>$value)   
{
		$ASTROLOGY_session[$key] = $value ;
		$ASTROLOGY_session[$key] = $HTTP_POST_VARS[$key];
}
the presence is tested with if (isset(ASTROLOGY_session))
 
PHP's behavior varies a lot within version 4. What subrevision?

First, if you're using a version of PHP newer than 4.1.0, I strongly recommend that you use the $_POST superglobal array rather than $HTTP_POST_VARS. PHP 5 will make instantiatio of the "long" arrays optional and, at least in RC2, defaults to having them turned off.

Second, use of session_register() is the less-preferred way of manipulating session variables.

Third, the second assignment statement, unless I am mistaken, is redundant.

session_start();
.
.
.
foreach($_POST as $key => $value)
{
$_SESSION['Astrology'][$key] = $value ;
}

You can still check for the presense of a variable using isset() or array_key_exists().



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Additionally, be aware that Sessions are handled differently in IE and Mozilla and Opera, if you're talking about real money here you need to think of those three browsers at a minimum.

Specifically note the differences when using tabbed browsing and when having multiple instances of the program running. I'd elaborate but I forget which does which at this moment.

IMO a properly designed site needs to decide what happens if I want to shop two sections of a store at one time in two windows... does adding to the cart in one affect the cart in the other, or should they be distinct? What if I log one off?
 

IE is one session per browser.

Gecko/Mozilla is one session per instance of program running on host machine.

Opera is the same on Win32 as Mozilla.

I would say that if a user is on IE, keep em on one cart.
Users of better browsers can do more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top