redirect to requested page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

redirect to requested page

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

using php how do I post or even get the page?
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Wait what are you trying to do? I really did not understand your last post.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

integrate the adding mechanism to the existing page.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Would HTTP_REFERRER redirect to the previous url?
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

yes it would.

For more in it...
:arrow: http://www.phpfreaks.com/phpref/125.php
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Thanks a lot for all of the help you have provided.

Apologies for all the questions...PHP is remarkable!!!

Thanks again.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post 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 :P

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.
Post Reply