Riparian Posted May 4, 2009 Share Posted May 4, 2009 Scenario : I add a product to the cart with a href call with the model number included. e.g. <a href=$_SERVER[php_SELF]?model=1234>Add to cart</a> On the page re-load model 1234 is added to cart. All fine so far... The client then clicks to go to the cart e.g. <a href=cart.php>Cart</a> Problem..... If the client uses the Browser Back Button this URL reloads <a href=$_SERVER[php_self]?model=1234>Add to cart</a> Which adds another entry into the cart. How can i prevent this ? Any help is greatly appreciated Link to comment https://forums.phpfreaks.com/topic/156724-solved-help-with-headers-and-back-button-please/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Two things you can do: 1. Don't use links to add data. 2. Check if the model exists. If so, don't add it. Link to comment https://forums.phpfreaks.com/topic/156724-solved-help-with-headers-and-back-button-please/#findComment-825271 Share on other sites More sharing options...
Riparian Posted May 4, 2009 Author Share Posted May 4, 2009 Thanks for the input Unfortunately both are not possible as I offer up to 100 products per page so I do not see how this be achieved any other way and a client is at liberty to add 2 of the same model number to the cart ( 2 must be added individually for later processing) Is there no other way ? Link to comment https://forums.phpfreaks.com/topic/156724-solved-help-with-headers-and-back-button-please/#findComment-825281 Share on other sites More sharing options...
Riparian Posted May 4, 2009 Author Share Posted May 4, 2009 I have figured a work around. Only record an entry if a session variable is set in the add program. Unset the session variable in the cart program so if they use the browser back button the entry will not be re-recorded. Unless anyone can see a downside to this method then perhaps this will help someone else. Cheers Link to comment https://forums.phpfreaks.com/topic/156724-solved-help-with-headers-and-back-button-please/#findComment-825302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.