Forum Moderators: coopster

Message Too Old, No Replies

Back button on redirect

         

apauto

6:13 am on Dec 17, 2010 (gmt 0)

10+ Year Member



Hi guys,

I have a script in an iframe.

When someone clicks "add to cart" in this iframe, the user is directed to a script that processes some data, and then uses that data to add an item to cart.

SO here is the flow:

User clicks add to cart
User is trasfered to a processing.php page
One the processing page finishes, it transfers ths user to cart.php

What happens is when the user is transfered to the cart.php, if they click on the back button, it sends them back to the processing page, adding another item to their cart.

What trick can I do (i tried to think of everything) to have the user be able to hit the back button and go to the catalog (the page where they see the "add to cart" button) so they can keep shopping?

Thanks for your help!

Matthew1980

7:36 am on Dec 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there apauto,

Are these operations in functions? If so, you could have redirects setup within a function so that they only action when other processes complete, and have some sessions/cookies created and destroyed at these points so that you can check on your progress, then it's a case of checking that the session/cookie data isset() then empty() or !isset() and !empty() and action the redirects based on that, this way the logic will 'lock out' from certain pages, and this means that if you try the back button the calls to those functions *should* direct you to only the page(s) that your cookies/sessions dictate.

There may be other solutions, but this works fine for some of my scripts.

Cheers,
MRb

apauto

4:50 pm on Dec 17, 2010 (gmt 0)

10+ Year Member



But even if you check it with sessions it will still automatically go back to the processing.php page when they hit the back button.

This is the problem I'm having...

rocknbil

5:01 pm on Dec 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What trick can I do (i tried to think of everything) to have the user be able to hit the back button and go to the catalog (the page where they see the "add to cart" button) so they can keep shopping?


Don't redirect. Combine your cart script with the processing script.

if ($add_to_cart) {
process_order();
}
else { show_catalog_or_order_page(); }

After process_order it should return to the catalog anyway with a cart updated message.

apauto

5:24 pm on Dec 17, 2010 (gmt 0)

10+ Year Member



rocknbil,

this is what I normally do on my sites, but on this particular site, I'm using an open source program that needs a special way of adding items to the cart.

Thanks for the ideas guys, keep them coming!

milocold

9:28 pm on Dec 17, 2010 (gmt 0)

10+ Year Member



Hi,

What's the special way of adding items to the cart?

I mean, if you can't encase the script you're currently using in an if/else block, you may need to create another file to process back button clicks.

M.Cold

apauto

9:32 pm on Dec 17, 2010 (gmt 0)

10+ Year Member



milocold - It adds it through AJAX/Cookies. The thing is, i can hack the cart to accept the insert of the product, but then when the open source cart releases updates, it will get wiped out. I'm trying to make this stand alone.

Is there a way to have PHP detect a back button press? I can do a ondetect, redirect back to the orignal referring page or something sneaky?

rocknbil

5:49 pm on Dec 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It adds it through AJAX/Cookies.


So then, can you check for the existence of the cookie when the first page loads and act accordingly?