473,781 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2480
B.r.K.o.N.j.A. (th********@ine t.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
12978
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). Better explanation: - Pages are: * Page A: Front-page
4
6934
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 click the button at the bottom, the next page will show which problems they got right or wrong. Now my visitors, after seeing some problems they got wrong, click Back button at the Explorer menu, and if they do, they get the below message:...
1
1590
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- revalidate, private" Response.AddHeader "Pragma", "no-cache"
1
5823
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 width="05%">&nbsp;</td> <TD width="90%" align=center valign=middle colspan=2> <BUTTON TYPE=BUTTON ONCLICK="location.href='<% = Request.ServerVariables("HTTP_REFERER") %>';"
5
2445
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 button). Is there any way I can keep the form for disabling every time a user hits the back button and "remember" what elements should be enabled? I was thinking maybe utilizing some referrer thing, but I'm not that good with JS yet. Thanks...
4
3259
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 one clicks some button goes to "detail" page - for to add/update data. That form may have number of postbacks. On
8
2585
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 courses are populated. When course is selected, lists of occurrences, groups and
6
3816
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 user get used to click "enter" key to submit a form. How can I use "enter" key to submit/postback in ASP.NET. Thank, Guoqi Zheng
7
2488
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 click on button1, it populates the text boxes with person1 details. When I click on button2, it populates the text box with person2 details and redirects to webform2. In webform2 if I click on Back Button of Internet Explorer it should display...
4
3195
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, and still keep all the other fields as they were written. If I use Response.Redirect the form will be loaded empty again. The same if I use a button on page 2 with onClick="history.Back". Isn't there a way to go back and keep the already written...
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.