Header

王朝百科·作者佚名  2010-03-27  
宽屏版  字体: |||超大  

标头 (header) 是服务器以 HTTP 协义传 HTML 资料到浏览器前所送出的字串,在标头与 HTML 文件之间尚需空一行分隔。有关 HTTP 的详细说明,可以参 RFC 2068 官方文件.

在 PHP 中送回 HTML 资料前,需先传完所有的标头。

范例一: 本例使浏览器重定向到 PHP 的官方网站。

//view plaincopy to clipboardprint?

<?php

Header("Location: http://www.php.net";);

exit;

?>

范例二:

//view plaincopy to clipboardprint?

<?php

if(xxx)

{

Header("Location: http://www.php.net");

}

else

{

Header("Location: http://www.php2.net");

}

?>

范例二可以简化为:

//view plaincopy to clipboardprint?

<?php

if(xxx)

{

Header("Location: http://www.php.net");

break;

}

?>

view plaincopy to clipboardprint?

<?php

/**

@title:PHP定时跳转

@author:axgle

@date:2005-11-04

@功能:等待指定的时间,然后再跳转到指定页面(代替html meta方式)

*/

header("refresh:3;url=http://axgle.za.net");

print('正在加载,请稍等...<br>三秒后自动跳转~~~');

/*

补充说明:

若等待时间为0,则与header("location:")等效。

*/

?>

控制文件编码:

header("Content-type: text/xml; charset=utf-8");

或者 header("Content-type:image/gif");

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有