Web Hosting Talk







View Full Version : php question


matt2kjones
09-29-2002, 10:10 AM
ok, i have a question about php, dunno if it is possible though

say i have a variable called $choice

can i do this sort of thing :

if ($choice == 1)

{

some code here to goto a page called choice1.php;

}

else

{

some code here to goto a page called choice2.php;

}

if so could you tell me the code to write which would take the page to choice1.php or choice2.php

cheers

webx
09-29-2002, 10:27 AM
if ($choice == 1)

{

Header("Location: choice1.php");

}

else

{

Header("Location: choice2.php");

}


:)

Lagniappe-labgeek
09-29-2002, 01:58 PM
And make sure you spit out nothing (but other headers) to the page before this, otherwise it won't work.

cortices
09-30-2002, 02:56 PM
Although the above method is ideal, as the previous post mentioned, you cannot use it if you have already commited the output to the browser.

The information sent to the browser is formed by the header followed the content. As you can see from the function name (header()), it sets HTTP headers. Now, these headers obviously cannot be sent if the content is already on its way to the browser.

Proper design will usually negate these issues, but I have found that sometimes it is necessary to have an alternative.

You can use the following HTML tag to redirect the browser.

<meta http-equiv="refresh" content="delay_in_seconds;url=http://someurlhere">

Hope this helps!