rachelk Posted February 23, 2010 Share Posted February 23, 2010 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 More sharing options...
jay7981 Posted February 23, 2010 Share Posted February 23, 2010 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..... } Link to comment https://forums.phpfreaks.com/topic/193037-redirecting-within-a-page/#findComment-1016639 Share on other sites More sharing options...
aleX_hill Posted February 23, 2010 Share Posted February 23, 2010 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. Link to comment https://forums.phpfreaks.com/topic/193037-redirecting-within-a-page/#findComment-1016644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.