Click to See Complete Forum and Search --> : PHP redirect url


djl35319
10-23-2006, 07:13 PM
Is there a way to launch a new web page without using the header command?
When I try to use header I get the following:

Warning: Cannot modify header information - headers already sent by

so_is_this
10-23-2006, 07:31 PM
"launch" from PHP? No. However, if you use outbound buffering then you can flush the buffer and go ahead to perform the redirect as normal. See:
ob_start();

NogDog
10-23-2006, 08:23 PM
Or just make sure your logic is such that nothing is output to the browser before your call to header(). (This includes having no newlines and/or spaces before the opening <?php tag.)

Michaelttkk
10-24-2006, 08:43 AM
is this what you were looking for?

<script>
location.href="new page.php";
</script>

so_is_this
10-24-2006, 10:19 AM
Yes, I editted my post to clarify that I was talking about from PHP. That code is JavaScript and, as such, may not work -- in the case that JavaScript may not be enabled or even available.

carlh
10-24-2006, 10:29 AM
then you have to have it before the header is sent or look into using an output buffer like so_is_this mentioned

djl35319
10-24-2006, 01:43 PM
using the Javascript worked perfectly. Thanks to all for the assistance on this.

knowj
10-24-2006, 01:49 PM
a lot of people have java script disabled so you should either provide a server side alternative or just use server side the code below WILL work

the ob_start(); and ob_end_flush(); stop the Warning: Cannot modify header information from appearing i also use this when i'm working with cookies

<?php
ob_start();

//your code
header("Location: http://www.url");
ob_end_flush();
?>