PHP:防止直接访问页面 [英] PHP: prevent direct access to page

查看:261
本文介绍了PHP:防止直接访问页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我不希望用户直接访问的页面.

I have some pages that I don't want users to be able to access directly.

我有这个功能可以使用:

I have this function I came up with which works:

function prevent_direct_access()
{
    if($_SERVER['REQUEST_URI'] == $_SERVER['PHP_SELF'])
    {
        //include_once('404.php');
        header("Location: 404.php");
    }
}

这正是我想要的,URL不会改变,但是内容会改变.但是我想知道是否需要添加一些内容来告诉搜索引擎这是404,而不是对其进行索引.请记住,我不想更改URL.

This does exactly what I want, the URL does not change but the content does. However I am wondering if there is something I need to add to tell search engines that this is a 404 and not to index it. keep in mind I do not want the URL to change though.

谢谢!

推荐答案

不重定向,但发送404状态代码:

Don’t redirect but send the 404 status code:

header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
exit;

这篇关于PHP:防止直接访问页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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