back command with php

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
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

back command with php

Post by sarris »

Hi there...Is there any way to redirect a page (php page) to the previous one, as if the user clicked the BACK button on his browser?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The data isn't reliably set, but there is $_SERVER['HTTP_REFERER']
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Javascript

Code: Select all

<a href="javascript:history.go(-1)">GO BACK</a>
PHP

Code: Select all

$PrevURL = $_SESSION['GoBack'];
header("Location: ".$PrevURL);
But in all your pages you go to include a $_SESSION['GoBack'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

Code: Select all

php:

$PrevURL = $_SESSION['GoBack'];
header("Location: ".$PrevURL);
used that and got this errror
Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/houseonmap.gr/httpdocs/removeShortList.php:28) in /home/httpd/vhosts/houseonmap.gr/httpdocs/removeShortList.php on line 30

i put this line

Code: Select all

$_SESSION['GoBack'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
to the involved pages.
Is it REQUEST_URI? or REQUEST_URL?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"headers already sent" has been talked about so much that very few people will rehash the fix.

As for your second question.. take a look in $_SERVER for yourself .. or search the boards for "getURL"
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

"headers already sent" has been talked about so much that very few people will rehash the fix
which means? no solution?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

if it's been talked about on the boards before, generally you should be able to find it by searching... :roll:
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

ok. will try to find the solution.
another question. is it true that redirection with javascript may cause your page to be removed from search engines?
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

i deleted any previous echo commands and all works fine.Thanks anyway
Post Reply