Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is PHP's version of Response.Redirect? 1

Status
Not open for further replies.

James1981

Programmer
Nov 2, 2002
76
US
Hi,

I'm new to PHP but am fluent in ASP. I want to redirect the browser to another URL in the same way that ASP uses Response.Redirect(url), but in PHP.

Is there an easy way?

Thanks in advance

James.
 
Like this:

Code:
<?php

header (&quot;Location: [URL unfurl="true"]http://www.mysite.com&quot;);[/URL]

?>
Regards
David Byng
spider.gif

davidbyng@hotmail.com
 
I have tried this but I get an error:

Warning: Cannot add header information - headers already sent by (path....)

anyway round this?
 
Yes.

Make sure that your script outputs no text to the browser before using header() for anything. ______________________________________________________________________
TANSTAAFL!
 
Know, too, that any warnings or errors that are printed to the browser screen count also count as output for the purpose of the header() function. ______________________________________________________________________
TANSTAAFL!
 
What happens if i need to output something to HTML using say echo &quot;something&quot; and this comes before the header() call?

How do i get round this?

Cheers
James.
 
how about this scenario?

echo &quot;something&quot;;
if (condition)
header(location: &quot;url&quot;);
echo &quot;condition is false&quot;;
 
Anything that affects the HTTP headers that PHP and the web server will send to the client must be done before any content is sent. This includes but is not limited to anything you do with header() [], setcookie() [], session_start() [], and session_cache_limiter() []. This is because PHP sends data to the browser, whether headers or content, as it is being produced.

There is a way around this: output buffering []. With output buffering, you can produce output in any order you wish, then send it all at once. You take a performance hit using output buffering, however, as PHP has to cache the output until ordered to send it. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top