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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i automtaic load another .php page?

Status
Not open for further replies.

Petal

Programmer
Jun 8, 2001
56
0
0
NO
Hi. I have one quite simple problem I think..

I have a if statement. If it is true I would like to load a page named yes.php. The code:

if($bol==1){
//load yes.php
}

How do I load this page automaticly in php? I know how to do it in html. But I would prefer to send just 1 page to the client.

 
you can use the header() function to do this

Code:
if ($bol==1){
header("location:yes.php");
}

be careful that u use this before outputing anything to the browser, because this function is used in the header section.

 
But, the header() function must be called before any other output to the browser. Notice I say output, not PHP parsing. In other words you can do all kinds of PHP logic to choose this or that, but the minute you echo even one ASCII character out to the browser, you lose your right to pass a header, because the webserver automatically generates a header as content goes to the browser.

The only way around this is to use PHP's output buffering functions, which allow you to parse a whole PHP page, do all your logic, echo values, etc... and take ALL of that output, and decide at the end of the script exactly what you want to do with it, including whether you want to discard content and go to another page. -------------------------------------------

"Calculus is just the meaningless manipulation of higher symbols"
                          -unknown F student
 
I've had great success creating my own php/javascript hybrid function. Cut and paste this into your code. call it like any other php function.

/**
* FUNCTION: php_location()
* Redirects the users browser to a new location
* @param: $newlocation: an URL
*/
php_location($newlocation){
echo("
<script language='javascript'>
location='&quot;.$newlocation.&quot;'
</script>
&quot;);
}

Regards,
Bryan C.
 
Why not just put your header() logic before any output. If you absolutely have put logic that generates output first, store that output in a variable and echo it later.

-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top