Jump to content

Redirecting within a page


rachelk

Recommended Posts

I wanted to know if it were possible to have something like this halfway down a page:

 

if { *something* }

else { *redirect to another page*}

 

Everything I've found requires the redirect to be at the very top of the page.. is it possible to have it within a page?

 

Any help much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/193037-redirecting-within-a-page/
Share on other sites

you can try javascript:

$goto = '/file.php'; 
echo <<<END 
<script language="javascript"><!-- 
window.location='$goto'; 
//--></script> 
END;  

 

or try the ob_start method using if

(must be first line in file)

ob_start
if ($var1=val1){
header(location .....
}else{
header(location.....
}

Is there a reason that you need to write to the page before you process the if statement.

 

I would put the processing part of the file at the top, and put the displaying part at the bottom. You can use a header() function anywhere as long as you havent written anything to the page first. Doesnt need to be at the top if it is only php processing before it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.