Jump to content

session_start and page refresh


ProblemHelpPlease

Recommended Posts

I am having an issue with a shopping basket displaying the wrong content when a client uses the back button. I had thought about adding a session_start() at the top of the page so that the basket content is reloaded correctly if the back button is used.I had initially tried not to use sessions as I hate sites that give a 'webpage expired' screen when using the back button.Am I correct in thinking this would not happen if the only session code I use is a session_start().Also is using session_start() likely to interefere with any other aspects of the site, like cookies and post data. The site is live and I cant afford to have any issues especially at this time of year.I have never really had a need to use sessions before so dont have the pratical knowledge of any potential problems.

Link to comment
Share on other sites

session data is saved in array, similar to POST or GET. You can just have the pages on your site check to see if anything has been saved in the SESSION array relating to cart information. If there is, show it, if there isn't, don't show it. The idea would be that if anyone has anything in their cart while on your site during one session, it shouldn't matter what page they're on, it will always show the cart if there's something in it, or show it empty if there isn't.

Link to comment
Share on other sites

I think that would require too much alteration to the live site at this stage. The site is not structured in such a way that it would be easy to implement your suggestion.I have tried adding session_start() at the top of the page and it appears to generate the required result in that using the back button forces the basket to reload the data correctly.If I can get away with using this method it would be much easier. Is creating a new session everytime a page is loaded likely to cause a problem with the server or with the clients PC? or does it overridea a previous session each time.

Link to comment
Share on other sites

why not read about them?http://www.php.net/manual/en/book.session.phpall I was suggesting is a simple if/else control structure

if(isset($_SESSION['cart_data'])){  echo "show cart data";}else{  echo "display an empty cart";};

It's just a way to handle displaying the cart so you don't get the session expired message you were talking about. Basically however you are storing the cart, you just have to save it to the $_SESSION array. It will persist in it's state on every page with session_start() but will only change unless your code specifically changes it. On the manual page it will will show what versions of PHP it's supported in. As long as your server supports it, then you don't worry about the clients. PHP only runs on the server.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...