Header() in PHP4

From: Date: Tue, 24 Aug 1999 21:53:14 +0000
Subject: Header() in PHP4
Groups: php.version4 
Request: Send a blank email to php-version4+get-3692@lists.php.net to get a copy of this message
People ask about the differences between PHP and Cold Fusion regularly. One thing that I liked about Cold Fusion was the CFLOCATION tag, which is works like the header() tag in PHP. One big difference between the CFLOCATION and header is that it is possible to have HTML and output on a page before the tag is called. For example (I am unsure of CF syntax): <HTML> <body> This is something <CFIF #VAR# is 3> <CFLOCATION location="page.html"> </CFIF> </body> </html> Whereas PHP requires: <? if($var==3) header("Location: page.html") ?> <html>.... Either way is easy to use, but there is sometimes an advantage in running some output before the page is redirected. I know this can be done with a <META> tag, but I don't like the fact that the user can hit Stop on the browser. The reason why I am asking about this feature in PHP4 is because I (maybe wrong) am under the impression the script is "compiled" completely before output is sent to the browser. I don't believe this was the case with 3. And I believe this is the way CF works. Sooo, is there anyway that this functionality can be added to version 4. This would also be a valuable feature for the SetCookie function. I don't always have the opportunity to set a cookie before any output has been sent consequently I use a function JSSetCookie(below) which works like SetCookie but prints Javascript out for the browser to pick up on. But that requires the user to have JS on. Any thoughts? Michael Stearne ------------------------------------------------------------------------------- function JSSetCookie($CName,$CValue,$CExpr=FALSE){ // $CXpr is in years // Will allow cookies to be set even after HTML has been printed on the page if($CExpr!=FALSE){ $CookieString="astr= '$CName' + '=' + '$CValue' + ';expires=' + expr + ';path=/';"; $Cookie.="\n<script language=\"javascript\">\n"; $Cookie.='function makeYearExpDate(yr){ var expire = new Date(); expire.setTime(expire.getTime() + ((yr *365) *24 * 60 * 60 * 1000)); expire = expire.toGMTString() return expire } expr =makeYearExpDate('.$CExpr.');'; $Cookie.="\n".$CookieString."\n"; $Cookie.="document.cookie=astr;\n</script>\n"; }else{ //$CookieString="astr= '$CName' + '=' + '$CValue' + ';expires=;path=/';"; $Cookie.="\n<script language=\"javascript\">\n"; $Cookie.="document.cookie='$CName=$CValue;path=/';"; $Cookie.="\n</script>\n"; } echo $Cookie; }

« previous php.version4 (#3692) next »