How to return any previous site in PHP
Moderator: General Moderators
How to return any previous site in PHP
Hello!
For example I have cart.php, and in this file:
<a href="products.php"><< Go back</a>
What I have do in PHP if I want to return always to the previuos site, without specify previous site, I mean return always to the location where cart.php is calling from.
Could anyone help?
Regards
For example I have cart.php, and in this file:
<a href="products.php"><< Go back</a>
What I have do in PHP if I want to return always to the previuos site, without specify previous site, I mean return always to the location where cart.php is calling from.
Could anyone help?
Regards
Last edited by tua1 on Thu May 22, 2008 1:51 pm, edited 1 time in total.
- aditya2071990
- Forum Contributor
- Posts: 106
- Joined: Thu May 22, 2008 11:30 am
- Location: Hyderabad, India
- Contact:
Re: How to return in previous site in PHP
use header(location:products.php) function, result I don't know thoroughly...better to test before you go ahead...and oh, use sessions to store all your variables, to make sure they are not destroyed...
Re: How to return in previous site in PHP
aditya2071990 wrote:use header(location:products.php) function, result I don't know thoroughly...better to test before you go ahead...and oh, use sessions to store all your variables, to make sure they are not destroyed...
Thanks for your reply, but my goal is to return to any previuos page.
header(location:any_previous_page.php) is this possible??
Regards
Re: How to return any previous site in PHP
You may use $_SERVER['HTTP_REFERER'], though it's no reliable.
There are 10 types of people in this world, those who understand binary and those who don't
-
whiterabbit
- Forum Newbie
- Posts: 14
- Joined: Thu May 22, 2008 6:58 pm
Re: How to return in previous site in PHP
This is possible. All you need to do is on the page before you go to your cart, you dotua1 wrote:aditya2071990 wrote:use header(location:products.php) function, result I don't know thoroughly...better to test before you go ahead...and oh, use sessions to store all your variables, to make sure they are not destroyed...
Thanks for your reply, but my goal is to return to any previuos page.
header(location:any_previous_page.php) is this possible??
Regards
$_SESSION['previous_page'] = http://www.yoursite.com/current_directory/$_SERVER['PHP_SELF']; // this will store in the users session variable the current page.
Then the user goes to the cart and does whatever it is that they do.
When you want to have your customer go back to the page that they came from you do a
header('Location: ' . $_SESSION['previous_page']);
Don't forget to put the $_SESSION['previous_page'] = http://www.yoursite.com/current_directory/$_SERVER['PHP_SELF']; on every page that they could come from.
Re: How to return any previous site in PHP
Won't window.history.back() work?
-
whiterabbit
- Forum Newbie
- Posts: 14
- Joined: Thu May 22, 2008 6:58 pm
Re: How to return any previous site in PHP
This would definitely be the easiest if...califdon wrote:Won't window.history.back() work?
1. We are going to assume that javascript is enabled for the clients
2. There is only 1 page in the cart.
Right??
Re: How to return any previous site in PHP
1. Yes, absolutely. If that's an issue, then I guess you'd need to use HTTP_REFERER.whiterabbit wrote:This would definitely be the easiest if...califdon wrote:Won't window.history.back() work?
1. We are going to assume that javascript is enabled for the clients
2. There is only 1 page in the cart.
Right??
2. I don't see that that makes any difference, it always goes back just one URL, and I thought that's what the OP asked for.
Re: How to return any previous site in PHP
Yes it is, thank you for your help
Regards
Regards