Click to See Complete Forum and Search --> : PHP running Scripts


shopkanji
11-03-2004, 10:51 PM
I have a link that loads a PHP page that has several if/else statements.

Depending on variables, one of several different outcomes occurs.

In all situations the user is redirected to a new page using a header line.

This works fine and great, and I don’t need any help here.

On some of the outcomes I would like a script to load.

If I try to use print line above the header line, but then my header line doesn’t work and I get an error: “Cannot modify header information - headers already sent by…”

How can I load a script with my PHP page and have my headers work?

Alternatively, is there any native PHP way to prompt a user to bookmark a page?


if ($var == "this")
{
header("Location: http://www.site-a.com/");
}
else
{
print (“<script>if (document.all); window.external.AddFavorite(\"http://www.site-b.com\",\"Site B\");</script>”);
header("Location: http://www.site-b.com/");
}

Thanks for any help! :)

Jupac
11-03-2004, 11:04 PM
if ($var == "this")
{
header("Location:http://www.site-a.com/");
}
else
{
print ("<script type=\"text/javascript\">if (document.all); window.external.AddFavorite("http://www.site-b.com\",\"Site B\");</script>");

header("Location:http://www.site-b.com/");
}

shopkanji
11-03-2004, 11:54 PM
I defined the script to javascript, make another line break between the print and header commands, and took out the space in the Location header but it still dosn't work.

It gives me the same error.

Jupac
11-03-2004, 11:56 PM
use echo instead of print

NogDog
11-04-2004, 08:30 AM
Once your PHP script sends any non-header output to the client, you can no longer perform a header() command, period.

Personally, I hate pages that pop up something asking if I want to bookmark it or make it my default page. But if you feel you must, maybe it should go on the pages that you get redirected to. You could check to see if the http referer is your redirect page, and only output the JavaScript in that case, perhaps?