i am attempting to build a simple login script where if the user successfully logs in it redirects them back to the page they came from. i just cant get it to do this?!!! can anyone help 😕
Originally posted by bailo81 i just cant get it to do this?!!! can anyone help 😕
Let's see some code...
well i know that to redirect a page you can use:
header ('Location: [url]http://www.example.com[/url]');
and that to get the previous page you can use :
$_SERVER['HTTP_REFERER']
but im having problems combining the two?!!
The HTTP "Location" header takes a URL (absolute, by specs, but a relative one will most always work), not an HTML link. So you could do it like this:
header('Location: ' . $_SERVER['HTTP_REFERER']);
i cant get that to work either for some reason, it just stays on the same page :queasy:
as for the link being in it, i think i must have just copied and pasted wrong!
it is working and i had it working with
header('Location: $_SERVER[\'HTTP_REFERER\']');
in the first place. as it stayed on the same page i assumed it wasnt working but as my login form submits to itself and then processes itself then i suppose the http_referer will also be itself!! hence my problem!
header('Location: $_SERVER['HTTP_REFERER']');
Are you sure that works? It shouldn't.
i actually had:
but when you enter code in that pop up code box on here it strips the slashes out
:queasy:
it stripped the slashes out on a normal post too ????
well i had backslashes in front of the apostrophes anyway!!
Well, the backslashes shouldn't help much, since variable names aren't evaluated inside single quotes. If it works, your parser is broken; if it doesn't, use the code I posted.