php redirects

Soldato
Joined
15 Sep 2003
Posts
9,454
Hey,

I'd like some advice on the following; I will use the forums as an example.

If I'm logged out from the forums and am viewing a thread. Decide to log in, I’m sent back to the thread I was viewing. I presume this is done via http_refferer?

I'm trying to implement this into a website of mine but can't seem to find the right stuff to use. If I use:

Code:
header('Location: '.$_SERVER['HTTP_REFERER']);

I receive an error stating headers already sent.

Is there any way of redirecting the user without using the above?

Cheers,

Jon
 
Last edited:
Headers already sent means there's already been output/whitespace sent to the client - double-check your script doesn't output anything if you need to redirect first :)
 
The problem is that I need to redirect after something is done.

The solution is dirty. :D.

Code:
echo "<a href=\"logout.php\">logout</a><br />";
	$ref=@$HTTP_REFERER;
	echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=".$ref."\">";
 
Back
Top Bottom