using header(location to avoid resubmission of form data
Posted: Tue Nov 25, 2008 2:34 pm
So I have a shopping cart with all code contained within the one page. It has functions for shopping cart actions of add, update, delete that update the db table based on the user action. The type of scenario I'm trying to tackle is if a user adds something to their cart then refreshes, it adds the item again. etc etc typical form resubmission issue.
So I had an idea, tested it, and it appears to work. But I'm concerned that I haven't seen this solution on these boards or google anywhere so maybe there's a problem that I'm not seeing that could occur by doing it this way.
Basically, user submits change to shopping cart -> Shopping cart add, delete, or update function is called. At the end of each function, I just added header('Location: cart.php'); So page loads, cart is updated, then header location is changed to cart.php with no POST data, so user can freely refresh, use back button, whatever they want. What am I overlooking? This seems TOO easy...
So I had an idea, tested it, and it appears to work. But I'm concerned that I haven't seen this solution on these boards or google anywhere so maybe there's a problem that I'm not seeing that could occur by doing it this way.
Basically, user submits change to shopping cart -> Shopping cart add, delete, or update function is called. At the end of each function, I just added header('Location: cart.php'); So page loads, cart is updated, then header location is changed to cart.php with no POST data, so user can freely refresh, use back button, whatever they want. What am I overlooking? This seems TOO easy...