lional Posted October 22, 2008 Share Posted October 22, 2008 I have created a site using mysql and php. When using sessions for the shopping cart, if the user presses the browser back button the previous page is not displayed only a page that says that this page has expired. I posted on the php help section and I was told that this can be done with AJAX. I am very new to AJAX in fact my book only arrived today. Can someone point me in the right direction so that I can accomplish the above. Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/ Share on other sites More sharing options...
rhodesa Posted October 22, 2008 Share Posted October 22, 2008 do you have an example page? Are you saying the following happens: -User navigates to an Item page -User clicks BUY ITEM, which does a POST to the shopping cart, adding the item -User navigates to another page -User clicks BACK BUTTON, which should take them to the shopping cart page, but it says the page has expired and asks if they want to re-post the data? Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-671849 Share on other sites More sharing options...
lional Posted October 22, 2008 Author Share Posted October 22, 2008 I have a page with all the products listed with a text box next to each item where the user can enter the quantity. This allows the user to select more than one item and purchase them all with one transaction. So he doesn't add one product to the cart and then add the second. So basically all the items are added to the cart and then the cart is viewed and the user can proceed to the checkout. But if the user adds say 5 products to the cart and then he goes to the view cart. If he clicks the back button to go back to the items page it says the webpage has expired. Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-671869 Share on other sites More sharing options...
rhodesa Posted October 22, 2008 Share Posted October 22, 2008 so, the expired message is caused by the user navigating back to a page that was generated with a POST. so, how does the user get to the 'items' page? Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-671874 Share on other sites More sharing options...
lional Posted October 22, 2008 Author Share Posted October 22, 2008 There is a navigation button that takes the user to the items page. The whole site was written so that the user can make all their selection once and then procedd to the checkout. On the view cart page the user can change their quantities and delete items. The site is a photo to canvas site so the user uploads their image and the items are various sizes of canvas that they would like the image to be on. at the end of the process the user can select a second image and repeat the process. Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-671883 Share on other sites More sharing options...
rhodesa Posted October 22, 2008 Share Posted October 22, 2008 i still don't understand where all your POSTs are happening. but what i do to avoid that message, is when I have a POST, i process the data, then use a header('Location: ...'); call to send them to a page (even if it's the same page). So, if you have something posting to cart.php for example, i would do this: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ //New items are being added //process those items here, saving the info into $_SESSION //Now send the page back to itself header('Location: '.$_SERVER['PHP_SELF']); exit; } //Now start the shopping cart //Get all the info for the cart from $_SESSION ?> make sense? this will also make it so if they refresh the page the POST goes to, it won't ask them if they want to resend the data p.s. - can a mod move this back to PHP? Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-671931 Share on other sites More sharing options...
lional Posted October 22, 2008 Author Share Posted October 22, 2008 go to the site www.canvasprintshop.co.za On the home page there is an order button which allows you to upload your image (image must be greater than 300K), then you select your edging, on the next page you select your finish, and then on the following page you select your items and press the order button. That will take you to a view cart.if you press the back button from this page you get the page expired Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-672039 Share on other sites More sharing options...
rhodesa Posted October 22, 2008 Share Posted October 22, 2008 right, so on all these pages, do you save the info that is being submitted into the SESSION? http://www.canvasprintshop.co.za/select_file.php http://www.canvasprintshop.co.za/effects.php http://www.canvasprintshop.co.za/order_price.php http://www.canvasprintshop.co.za/view_cart.php Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-672057 Share on other sites More sharing options...
lional Posted October 23, 2008 Author Share Posted October 23, 2008 yes Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-672490 Share on other sites More sharing options...
rhodesa Posted October 23, 2008 Share Posted October 23, 2008 so then use the method i showed before on all those pages. store the info into session. the use HEADER() to forward to PHP_SELF. that will make the error go away Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-672528 Share on other sites More sharing options...
lional Posted October 23, 2008 Author Share Posted October 23, 2008 thanks Quote Link to comment https://forums.phpfreaks.com/topic/129572-ajax-and-using-the-back-button/#findComment-672531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.