通过直接键入php文件防止用户访问php文件

通过直接键入php文件防止用户访问php文件,php,security,Php,Security,有一个php文件。我想通过在浏览器中键入url来阻止用户访问该文件。(例如:abc.xyz/test.php),但当php文件从网站本身重定向时,用户将能够访问该文件。(例如:如果用户单击一个链接,它将加载test.php) 可以吗?将.htaccess文件上载到您的wp内容文件夹中。查看是否已经存在一个,然后将此代码附加到文件末尾。如果没有,只需创建一个新的空白文件并将以下代码添加到其中: RewriteEngine On RewriteCond %{HTTP_REFERER} !^http:

有一个php文件。我想通过在浏览器中键入url来阻止用户访问该文件。(例如:abc.xyz/test.php),但当php文件从网站本身重定向时,用户将能够访问该文件。(例如:如果用户单击一个链接,它将加载test.php)


可以吗?

将.htaccess文件上载到您的wp内容文件夹中。查看是否已经存在一个,然后将此代码附加到文件末尾。如果没有,只需创建一个新的空白文件并将以下代码添加到其中:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourwebsite\.com/ [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(gif|png|jpg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*\.(gif|png|jpg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov)$ http://yourwebsite.com/ [NC]

一种方法是使用cookies(大多数流行网站都使用)

test.php

<?php
//Check if user has permission
if(isset($_COOKIE["allow_access"]))
{
    //delete access after visiting the page
    setcookie("allow_access","",time()-3600);
}
else
{
    header("location: index.html");
}
?>
<?php
setcookie("allow_access","true");
header("location: test.php");
?>

allow.php

<?php
//Check if user has permission
if(isset($_COOKIE["allow_access"]))
{
    //delete access after visiting the page
    setcookie("allow_access","",time()-3600);
}
else
{
    header("location: index.html");
}
?>
<?php
setcookie("allow_access","true");
header("location: test.php");
?>

index.html

<html>
...
<a href="allow.php">Link</a>
...
</html>

...
...

在某种程度上是这样的,尽管答案太宽泛,无法涵盖。有关于这方面的教程吗?请参阅。还有一个术语:
路径遍历
。谢谢。但这不是wordpress的博客。这还能用吗?它是否需要任何更改,因为它不适用于wordpress博客。@Epodax如果您正确查看test.php,在第一条If语句中,我们将在访问页面后删除访问权限。无论如何,这只是一个示例想法,这里有很多缺陷。你需要根据你的站点需要来实现它。啊,你这么做了,我错了。