Page 1 of 1
redirect to requested page
Posted: Mon Mar 13, 2006 8:13 pm
by aceconcepts
Hi,
I am setting up a shopping cart.
When a customer adds an item to their shopping cart and the action for adding that item is carried out, how do I redirect the customer back to the page from which the item was added?
or
How can I add the item and simply refresh the current page from which the item was added?
Thanks.
Nick
Posted: Mon Mar 13, 2006 8:26 pm
by feyd
make a post or get request to the page with a signal to add the item to their cart (and making note of the action success or failure on the page)
Posted: Mon Mar 13, 2006 8:36 pm
by aceconcepts
using php how do I post or even get the page?
Posted: Mon Mar 13, 2006 8:37 pm
by nickman013
Wait what are you trying to do? I really did not understand your last post.
Posted: Mon Mar 13, 2006 8:48 pm
by aceconcepts
sorry,
using a post or get request, how do I get the url of the page from which an item is added to the shoping cart?
I need to be able to add an item to the shopping cart and then redirect the cusotmer back to the original page from which they added the item.
Posted: Mon Mar 13, 2006 8:52 pm
by feyd
integrate the adding mechanism to the existing page.
Posted: Mon Mar 13, 2006 8:53 pm
by John Cartwright
$_SERVER['http_refferer'], although this may not always exist depending on browser and browser settings.
Usually I just pass the link in the url so I know where to redirect.
Posted: Mon Mar 13, 2006 8:54 pm
by nickman013
So basically, you want to view the dvd... lets say "Exorcist" , and you hit add to cart. You want it to add to the cart, and then redirect back to the page automatically or provide a link?
Well If you would like to provide a link you can just $_POST the HTTP_REFERER (not reliable).
So you can do this on the add to cart page.
Code: Select all
<?
$lastpage = $_SERVER['HTTP_REFERER'];
echo "<a href=$lastpage>Go Back To the Item</a>";
?>
I am not sure if that is what you mean.
Posted: Tue Mar 14, 2006 3:14 am
by aceconcepts
I would like to be able to automatically go back to the original page.
I understand what you say but I don't know how to 'pick up'/store the original page url!
i.e. if I was to store the original page url in a session variable how would I literally do this? What would the code look like?
Code: Select all
<?
$lastpage = $_SERVER['HTTP_REFERER'];
echo "<a href=$lastpage>Go Back To the Item</a>";
?>
How would I set $lastpage and when would I set it.
Thanks for your patience.
Posted: Tue Mar 14, 2006 3:15 am
by aceconcepts
Would HTTP_REFERRER redirect to the previous url?
Posted: Tue Mar 14, 2006 1:32 pm
by nickman013
Posted: Tue Mar 14, 2006 7:29 pm
by aceconcepts
Thanks a lot for all of the help you have provided.
Apologies for all the questions...PHP is remarkable!!!
Thanks again.
Posted: Wed Mar 15, 2006 8:04 am
by blacksnday
Not all browsers pass Referrer Info.
From my logs, I have found it is sometimes hard to rely on it.
This is what I use on all my rating forms
which allows any rating on any page to return
back immediately to the article they were on
without even knowing it
Code: Select all
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = $_SERVER['REQUEST_URI'];
header("Location: http://{$host}{$uri}{$extra}");
exit;
So if they voted on comment.php?bash=4
they return right back to it after rating it.