473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Back button and get request...

I've made a script for managing shoppingcart (something like
cart.php?action=add&item=12345) and it works fine, the problem is: when user
hits the back button page after he added something in the cart, the add cart
script is rerun and he ends up with having 2 of the same item. Is there a
way to prevent script from running when accessed via back button?

Thanks

Brko
Jul 17 '05 #1
5 2466
B.r.K.o.N.j.A. (th********@inet.hr) wrote:
: I've made a script for managing shoppingcart (something like
: cart.php?action=add&item=12345) and it works fine, the problem is: when user
: hits the back button page after he added something in the cart, the add cart
: script is rerun and he ends up with having 2 of the same item. Is there a
: way to prevent script from running when accessed via back button?

use POST (personally I dislike POST, but this is exactly the sort of
situation for which is is intended).

OR, change your logic. Instead of adding something, your logic can
indicate how many are wanted. If someone reruns the script then it
doesn't matter because the new value of how-many-wanted is simply the same
as the previous value of how-many-wanted.

OR, use a serial number of some kind so that you can detect when a query
is being re-run and not add the item.

OR, use the refer field and don't update unless your form is the refer.
The refer is no good for security, but is very useful as a convenience at
times like this.

OR, use cookies in conjunction with the request. You need javascript
though. Your forms use java script to always set a cookie to indicate the
data is being submitted from a form. The server always resets the cookie
in its responses. So if a user goes back to the page then the cookie
isn't set so your handler doesn't do anything (it just responds with a
form with the various values as defaults).

I used a serial number scheme once. One problem was that a cached form
will have an old serial number so the user gets an error if they try to
resubmit the data (easy to recover from but annoying). Using cookies
(without java script, but just to track the last serial number) might have
been better. (Your cart probably needs cookies anyway).

I'm sure there are other techniques, but those spring to mind.

$0.04

--

This space not for rent.
Jul 17 '05 #2
Go a redirect (to the shopping cart page, for instance) after the item
has been added.

Jul 17 '05 #3
That's it, clean and simple. I've came up with the lock field in cart object
(lock after update, unlock on pages where user can browse items), but I like
this one better, thanks.

Best regards,

Brko
Jul 17 '05 #4
Thank you, I came up with something (I've described it in reply to chung
leong) but I'll try these too.

Best regards,

Brko
Jul 17 '05 #5
B.r.K.o.N.j.A. wrote:
I've made a script for managing shoppingcart (something like
cart.php?action=add&item=12345) and it works fine, the problem is: when user hits the back button page after he added something in the cart, the add cart script is rerun and he ends up with having 2 of the same item.
That's really a good feature; the user might want to do that. To
handle that cleanly, the item id has to be pushed into the hash;
something like CART[itemid] = count.
Is there a
way to prevent script from running when accessed via back button?


Avoiding back button by redirecting and other means is kind of
breaking user friendlines. I wouldn't want to browse such site.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jarkko Kähkönen | last post by:
Hi! I have Windows XP&IE6.0.2... (SP1). I'm coding one project with PHP. I get "Warning: Page has Expired" when I try to get back to the "POSTed page" (page whither moved from FORM-page). ...
4
by: John | last post by:
Could anyone please help me on this?? I have a php script page, which is basically quiz. Visitors (after login in with their email address) are supposed to answer each question, and when they...
1
by: jim gigurtsis | last post by:
I am trying to get the BACK button to re-post the request to the server for IE 5+. I have used, Response.ExpiresAbsolute = #1/1/1980# Response.AddHeader "cache-control", "no_store, must-...
1
by: JJA | last post by:
When my webserver does not process a user's change because of an invalid password, I inform the user and I want to present them a button for a retry: <TR id=continuebuttonrow> <td...
5
by: Dani | last post by:
Hello everybody, I have some code that disables form elements on body load, but I notice when I hit the "back" button, I need to re-enable the form elements (that is done by clicking on a radial...
4
by: Bratislav Jevtic | last post by:
hi, ASP.NET, framework 1.0, patch 2, Windows 2000 server is this possible: from server side to say "go back" to browser? ------------------- scenario: I've got some page with a list. When...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
7
by: Sridhar | last post by:
Hi, I have a question regarding the Page_Load method and Back Button of Internet explorer. I have created a webform. In that webform I have several Text Boxes. Also I have two buttons. When I...
4
by: Rolf Rosenquist | last post by:
From a page with a form I collect the fields in the next page. The fields are compared with a database and if a certain condition does not fit, I want to go back to the first page with the form,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.