I'm working on wordpress plugin, which handles shopping cart. I have two pages, checkout and thank you page. Items to cart are added by link like that https://mysite.com/checkout/?action=add&subscription=23 . I'm using Session for adding items to the cart on checkout page.
Suppose if I add three items added: https://mysite.com/checkout/?action=add&subscription=1 https://mysite.com/checkout/?action=add&subscription=2 https://mysite.com/checkout/?action=add&subscription=3 (Last link in browser addressbar)
When user checkout on checkout page then user is redirected to thank you page. I have problem with browser back button, If user press back button on thank you, he is redirected again to checkout page with last item again added (https://mysite/checkout/?action=add&subscription=3 ) since this was the last link in browser address bar.
How can i prevent browser to add last item again on user back button press on thank you page? Is there any way in PHP to detect if request is coming from browser back button? I think, there can be way to handle it using session?
Please guide me if there is any other suitable way to accomplish this? Thanks
The best way to handle that is to use the POST/REDIRECT/GET pattern.
You can user $_SERVER['HTTP_REFERER']
to see your parent page, and detect if user is coming from thank you page
Use Post Redirect Get design pattern.
In other words, the script that processes is not the one that displays the results.