¡¡¡¡

header()º¯ÊýµÄÖ÷Òª¹¦ÄÜÊǽ«HTTPÐÒé±êÍ·(header)Êä³öµ½ä¯ÀÀÆ÷¡£
Óï·¨£º
void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) ¿ÉÑ¡²ÎÊýreplaceÖ¸Ã÷ÊÇÌæ»»Ç°Ò»ÌõÀàËÆ±êÍ·»¹ÊÇÌí¼ÓÒ»ÌõÏàͬÀàÐ͵ıêÍ·£¬Ä¬ÈÏÎªÌæ»»¡£
µÚ¶þ¸ö¿ÉÑ¡²ÎÊýhttp_response_codeÇ¿ÖÆ½«HTTPÏàÓ¦´úÂëÉèΪָ¶¨Öµ¡£ headerº¯ÊýÖÐLocationÀàÐ͵ıêÍ·ÊÇÒ»ÖÖÌØÊâµÄheaderµ÷Ó㬳£ÓÃÀ´ÊµÏÖÒ³ÃæÌø×ª¡£×¢Ò⣺1.locationºÍ¡°:¡±ºÅ¼ä²»ÄÜÓпոñ£¬·ñÔò²»»áÌø×ª¡£
¾ÙÀý£º
1 2 3 4 5 6 7 | <html>php/* This will give an error. Note the output * above, which is before the header() call */header('Location: http://www.example.com/');exit;?> |
¡¡¡¡
×¢Ò⣺
Meta±êÇ©ÊÇHTMLÖиºÔðÌṩÎĵµÔªÐÅÏ¢µÄ±êÇ©£¬ÔÚPHP³ÌÐòÖÐʹÓøñêÇ©£¬Ò²¿ÉÒÔʵÏÖÒ³ÃæÌø×ª¡£ Èô¶¨Òåhttp-equivΪrefresh,Ôò´ò¿ª¸ÃÒ³ÃæÊ±½«¸ù¾Ýcontent¹æ¶¨µÄÖµÔÚÒ»¶¨Ê±¼äÄÚÌø×ªµ½ÏàÓ¦Ò³Ãæ¡£
1 2 3 | < meta http-equiv="refresh"content="1;url=http://www.baidu.com"> |
¡¡¡¡
ͨ¹ýʹÓÃwindows.location.href=¡®url¡¯; ÊÇÒ³Ãæ×Ô¶¯Ìø×ªµ½ÐµĵØÖ·
1 2 3 4 5 6 7 | < ?php $url = "http://www.baidu.com"; echo "< script language='javascript'type='text/javascript'>"; echo "window.location.href='$url'"; echo "< /script>"; ?> |
¡¡¡¡