簡體   English   中英

通過直接輸入來阻止用戶訪問php文件

[英]Prevent users from accessing php files by typing it directly

有一個PHP文件。 我想通過在瀏覽器中鍵入URL來防止用戶訪問該文件。 (例如:abc.xyz/test.php),但是當該PHP文件從網站本身重定向時,用戶將能夠訪問該文件。 (例如:如果用戶單擊鏈接,它將加載test.php)

可能嗎?

將.htaccess文件上傳到wp-content文件夾中。 看一下是否已經存在,然后將此代碼附加到文件末尾。 如果您沒有,則只需創建一個新的空白文件並向其中添加以下代碼:

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]

一種方法是使用Cookie( 大多數流行的網站都使用

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");
}
?>

allow.php

<?php
setcookie("allow_access","true");
header("location: test.php");
?>

index.html

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM