PHP标题'HTTP / 1.1 403 Forbidden' [英] PHP header 'HTTP/1.1 403 Forbidden'

查看:95
本文介绍了PHP标题'HTTP / 1.1 403 Forbidden'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的PHP页面顶部 page04.php ,我有这个标题:

Hi,

On the top of my PHP page page04.php, I''ve this header:

<?php header('HTTP/1.1 403 Forbidden'); ?>



但是当我去 page04.php 使用我的浏览器,我没有得到403错误页面,但是 page04.php 的内容。我正在使用Apache HTTP服务器,这是我的 .htaccess 文件:


But when I go to page04.php with my browser, I don''t get a 403 error page, but the contents of page04.php. I''m using an Apache HTTP server, and this is my .htaccess file:

ErrorDocument 404 /404.php
ErrorDocument 403 /403.php



我也试过 HTTP / 1.0 而不是 HTTP / 1.1

为什么我没有收到403错误页面?我如何配置服务器,我的 .htaccess 文件或我的 page04.php 文件来获取我的403错误页面当我去 page04.php



提前致谢。


I tried also HTTP/1.0 instead of HTTP/1.1.
Why I don''t get my 403 error page? And how can I configure the server, my .htaccess file or my page04.php file to get my 403 error page when I go to page04.php?

Thanks in advance.

推荐答案

(此http状态代码的简短说明: http://www.checkupdown.com/ status / E403.html [ ^ ])



问题是,只需在页面开头放置403状态代码就不会有任何影响。 Web服务器(在您的情况下为Apache)决定请求是未经授权的,而不是您的代码。既然它可以执行php脚本而不是授权,对吧?因此,即使您发送403状态代码,也会发送内容,而这就是所有,Apache不会拦截您的状态代码。浏览器很乐意显示它:)。你在.htaccess中设置的只对Apache有效,php与它无关。



所以,如果你想从代码重定向到你的错误页面,只需添加 http位置 [ ^ ]重定向状态码后,立即退出php脚本。



如果你只想要要测试错误页面,只需创建一个虚拟文件夹并在其中设置.htaccess即可拒绝所有人。如果你做得对,你会得到错误页面。
(A short description of this http status code: http://www.checkupdown.com/status/E403.html[^])

The problem is, that simply putting a 403 status code at the beginning of the page won''t have any effect. The web server (Apache in your case) is deciding that the request is unauthorized, not your code. Since if it can execute the php script than it is authorized, right? So even if you send the 403 status code, you send the content also, and that''s all, Apache won''t intercept your status code. And the browser will be happy to display it :). What you set in .htaccess is only valid for Apache, php has nothing to do with it.

So, if you want to redirect from code to your error page, just add a http location[^] redirect after the status code, and exit immediately the php script.

If you want only to test the error page, just create a dummy folder and set .htaccess in it to deny everybody. If you made it correctly, you will get you error page back.


这篇关于PHP标题'HTTP / 1.1 403 Forbidden'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆