1. php中header()作用
header的用法
标头 (header) 是服务器以 HTTP 协义传 HTML 资料到浏览器前所送出的字串,在标头
与 HTML 文件之间尚需空一行分隔。有关 HTTP 的详细说明,可以参 RFC 2068 官方文件
(http://www.w3.org/Protocols/rfc2068/rfc2068)。在 PHP 中送回 HTML 资料前,需先
传完所有的标头。
注意: 传统的标头一定包含下面三种标头之一,并只能出现一次。
Content-Type: xxxx/yyyy
Location: xxxx:yyyy/zzzz
Status: nnn xxxxxx
在新的多型标头规格 (Multipart MIME) 方可以出现二次以上。
使用范例
范例一: 本例使浏览器重定向到 PHP 的官方网站。
Header("Location: http://www.php.net";);
exit;
>?
范例二: 要使用者每次都能得到最新的资料,而不是 Proxy 或 cache 中的资料,可以使用下列的标头
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
>?
范例三: 让使用者的浏览器出现找不到档案的信息。
header("Status: 404 Not Found");
>?
范例四:让使用者下载档案。
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=文件名\");
header("Content-Description: PHP3 Generated Data");
?>
header重定向 就等价于替用户在地址栏输入url
---------------------------------
//刚好找到比较详细的资料!
2. PHP语言解释
Header函数的功能是输出 HTTP 协议的标头到浏览器。
//设置地址被永久的重定向
header('HTTP/1.1 301 Moved Permanently');
//转到一个新网址,这个网址由变量$siteurl和$request_uri动态生成
header('Location: '.$siteurl.$request_uri);
还有很多其他的header,具体请查阅html手册,以下是一些相对常用的:
范例一: 本例用来重导用户到 PHP 的官方网站。
<?php
Header("Location: http://www.php.net");
exit;
?>
范例二: 欲让用户每次都能得到最新的资料,而不是 Proxy 或 cache 中的资料,可以使用下列的标头
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
范例三: 让用户的浏览器出现找不到文件的信息。
<?php
header("Status: 404 Not Found");
?>
范例四: [email protected] (28-Apr-1999) 提供让用户下载文件的范例。
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=some-file.tar.gz");
header("Content-Description: PHP3 Generated Data");
3. php动态页面设置了header("Status: 404 Not Found");但返回200状态
if($id!=1){
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
exit();
}
或者
if($id!=1){
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
exit();
}
4. 用php设置header返回404 但是页面空白 是不是和php.ini/nginx有关
404 not found
未找到该网页,说明此网页已经在服务器被删除或被改名。在安全助手里添加黑名单,把这个网站的网址输入进去。不让他弹出。
404是对NOT FOUND这种错误情况的一个编码,HTTP协议的错误信息在不同软件、不同的语言描述可能不同,但是其代码是统一的,以便浏览器能够正确识别和处理。
5. tp5 关于自定义404页面的,有大神来看下吗
1、对于存在的网页内容由于路径改变而导致访问不了时,可在IIS中定义404错误指向一个动态页面,在页面里面使用301永久重定向跳转到新的地址,此时服务器返回301状态码。2、设置404指向一个设计好的html文件,此时页面返回的404状态码。现在的idc提供商基本都提供404设置的功能,直接上传文件设置即可。在IIs中设置方法:打开IIS管理器-->点击要设置自定义404的网站的属性-->点击自定义错误选项-->选中404页-->选中并打开编辑属性-->设置成URL-->URL里填写“/err404.html”-->按确定退出再把做好的err404.html页面上传到网站根目录下。此处在“消息类型”中一定要选择“文件”或“默认值”,而不要选择“URL”,不然,将导致返回“200”状态码。3、把404指向一个动态页面,比如error.asp,如果不在页面里面进行设置,仅仅是返回提示的HTML代码,将导致页面返回200状态码,这是不正确的,我们可以在显示完提示内容后,增加语句:Response.Status="404NotFound",这样就保证页面返回404状态码。4、Apache下设置404错误页面。为ApacheServer设置404错误页面的方法很简单,只需在.htaccess文件中加入如下内容即可,ErrorDocument404/notfound.php。404页面就是当用户访问某网站时,点击了错误的链接时,所返回的页面。最常见的出错提示:404NotFound。其目的就是告诉浏览者其所请求的页面不存在或链接错误,同时引导用户使用网站其他页面而不是关闭窗口离开。错误页面的文字可以自定义,有些网站没有设置404错误页面,或者是直接采取的跳转到首页,这样一般都说对搜索引擎不是很友好。导致网页404错误的原因一般来说有几种情况:1、无法在所请求的端口上访问Web站点。2、Web服务扩展锁定策略阻止本请求。3、MIME映射策略阻止本请求。4、网站更新改版,但某些局部板块沿用原来的模块,而原有的模块调用的文件已经被删除或转移了路径。5、跟踪访问的各类脚码或CSS文件无效但调用代码依然存在。6、某个目录直接删除(导致一段时间该目录的文件在被爬行时全部报404NotFound错误)7、网页URL生成规则改变、网页文件更名或移动位置、导入链接拼写错误等,导致原来的URL地址无法访问
6. php中header() 有什么用
header的用法
标头 (header) 是服务器以 HTTP 协义传 HTML 资料到浏览器前所送出的字串,在标头
与 HTML 文件之间尚需空一行分隔。有关 HTTP 的详细说明,可以参 RFC 2068 官方文件
(http://www.w3.org/Protocols/rfc2068/rfc2068)。在 PHP 中送回 HTML 资料前,需先
传完所有的标头。
注意: 传统的标头一定包含下面三种标头之一,并只能出现一次。
Content-Type: xxxx/yyyy
Location: xxxx:yyyy/zzzz
Status: nnn xxxxxx
在新的多型标头规格 (Multipart MIME) 方可以出现二次以上。
使用范例
范例一: 本例使浏览器重定向到 PHP 的官方网站。
Header("Location: http://www.php.net";);
exit;
>?
范例二: 要使用者每次都能得到最新的资料,而不是 Proxy 或 cache 中的资料,可以使用下列的标头
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
>?
范例三: 让使用者的浏览器出现找不到档案的信息。
header("Status: 404 Not Found");
>?
范例四:让使用者下载档案。
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=文件名\");
header("Content-Description: PHP3 Generated Data");
?>
header重定向 就等价于替用户在地址栏输入url
7. php中如何让页面返回404错误代码呢
一般在空间商的网站里面的个人控制面板里面都有页面错误设置,不不用那么麻烦。
8. 为什么php页面顶部加了header("HTTP/1.1 404 not found");代码,程序还是往下执行
不会,他只会返回一个404状态码,还会向下执行。
9. 安装PHP是报错,求助
主页index.php代码如下:
PHP code?
<?php
require 'lib/core/DBAccess.class';
require 'lib/core/Object.class';
require 'action/default/WebBase.class.php';
require 'action/default/WebLoginBase.class.php';
require 'config.php';
//print_r($_SERVER);exit;
$para=array();
if(isset($_SERVER['PATH_INFO'])){
$para=explode('/', substr($_SERVER['PATH_INFO'],1));
if($control=array_shift($para)){
if(count($para)){
$action=array_shift($para);
}else{
$action=$control;
$control='index';
}
}else{
$control='index';
$action='main';
}
}else{
$control='index';
$action='main';
}
$control=ucfirst($control);
if(strpos($action,'-')!==false){
list($action, $page)=explode('-',$action);
}
$file=$conf['action']['modals'].$control.'.class.php';
if(!is_file($file)) notfound('找不到控制器');
try{
require $file;
}catch(Exception $e){
print_r($e);
exit;
}
if(!class_exists($control)) notfound('找不到控制器1');
$jms=new $control($conf['db']['dsn'], $conf['db']['user'], $conf['db']['password']);
$jms->debugLevel=$conf['debug']['level'];
if(!method_exists($jms, $action)) notfound('方法不存在');
$reflection=new ReflectionMethod($jms, $action);
if($reflection->isStatic()) notfound('不允许调用Static修饰的方法');
if(!$reflection->isFinal()) notfound('只能调用final修饰的方法');
$jms->controller=$control;
$jms->action=$action;
$jms->charset=$conf['db']['charset'];
$jms->cacheDir=$conf['cache']['dir'];
$jms->setCacheDir($conf['cache']['dir']);
$jms->actionTemplate=$conf['action']['template'];
$jms->prename=$conf['db']['prename'];
$jms->title=$conf['web']['title'];
if(method_exists($jms, 'getSystemSettings')) $jms->getSystemSettings();
if($jms->settings['switchWeb']=='0'){
$jms->display('close-service.php');
exit;
}
if(isset($page)) $jms->page=$page;
if($q=$_SERVER['QUERY_STRING']){
$para=array_merge($para, explode('/', $q));
}
if($para==null) $para=array();
$jms->headers=getallheaders();
if(isset($jms->headers['x-call'])){
// 函数调用
header('content-Type: application/json');
try{
ob_start();
echo json_encode($reflection->invokeArgs($jms, $_POST));
ob_flush();
}catch(Exception $e){
$jms->error($e->getMessage(), true);
}
}elseif(isset($jms->headers['x-form-call'])){
// 表单调用
$accept=strpos($jms->headers['Accept'], 'application/json')===0;
if($accept) header('content-Type: application/json');
try{
ob_start();
if($accept){
echo json_encode($reflection->invokeArgs($jms, $_POST));
}else{
json_encode($reflection->invokeArgs($jms, $_POST));
}
ob_flush();
}catch(Exception $e){
$jms->error($e->getMessage(), true);
}
}elseif(strpos($jms->headers['Accept'], 'application/json')===0){
// AJAX调用
header('content-Type: application/json');
try{
//echo json_encode($reflection->invokeArgs($jms, $para));
echo json_encode(call_user_func_array(array($jms, $action), $para));
}catch(Exception $e){
$jms->error($e->getmessage());
}
}else{
// 普通请求
header('content-Type: text/html;charset=utf-8');
//$reflection->invokeArgs($jms, $para);
call_user_func_array(array($jms, $action), $para);
}
$jms=null;
function notfound($message){
header('content-Type: text/plain; charset=utf8');
header('HTTP/1.1 404 Not Found');
die($message);
}
10. PHP中关于 header问题~~
$_POST['Submit']为真并且$_POST['password'] != $_POST['password2']时才能跳转到signup.php?error=pass