Page 1 of 1

back command with php

Posted: Wed Feb 28, 2007 9:30 am
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?

Posted: Wed Feb 28, 2007 9:44 am
by feyd
The data isn't reliably set, but there is $_SERVER['HTTP_REFERER']

Posted: Wed Feb 28, 2007 10:00 am
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'];

Posted: Wed Feb 28, 2007 10:31 am
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?

Posted: Wed Feb 28, 2007 10:35 am
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"

Posted: Wed Feb 28, 2007 1:02 pm
by sarris
"headers already sent" has been talked about so much that very few people will rehash the fix
which means? no solution?

Posted: Wed Feb 28, 2007 1:15 pm
by Luke
if it's been talked about on the boards before, generally you should be able to find it by searching... :roll:

Posted: Wed Feb 28, 2007 3:40 pm
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?

Posted: Wed Feb 28, 2007 4:34 pm
by sarris
i deleted any previous echo commands and all works fine.Thanks anyway