简体   繁体   English

防止直接访问URL

[英]prevent direct url access

I have a website and all the connectivity (with the database and other) are in a folder. 我有一个网站,所有连接(与数据库和其他连接)都在一个文件夹中。 Although there is a session on the restricted pages to prevent not logged users, these files may be reached if typed the full url(even if the php does show anything i guess its not a good thing). 尽管在受限制的页面上有一个会话来防止未登录的用户,但是如果键入完整的url,则可能会到达这些文件(即使php确实显示了任何东西,我猜这也不是一件好事)。 And the folder itself can be seen like a directory on the server, which is very bad. 而且文件夹本身可以看成是服务器上的目录,这非常糟糕。

www.mysite.com/connectionfolder

How can I deal with this problem? 我该如何解决这个问题? thanks! 谢谢!

Apache: Add the line below in your root .htaccess file Apache:在您的.htaccess根文件中添加以下行

Options -Indexes

If there is a line Options Indexes already in existing .htaccess file than you can simply modify it with Options -Indexes 如果现有.htaccess文件中已经有一行Options Indexes ,那么您可以简单地使用Options -Indexes对其进行修改

This will have Apache preventing direct directory access. 这将使Apache阻止直接目录访问。

If you use Apache put a .htaccess file in your root web directory if one is not already there. 如果使用Apache,则将.htaccess文件放在根Web目录中(如果尚未存在)。 Then put this in the file: 然后将其放入文件中:

Options -Indexes 

More info: https://httpd.apache.org/docs/current/mod/core.html#options 更多信息: https : //httpd.apache.org/docs/current/mod/core.html#options

You can also redirect the user away from the "secure" pages 您还可以将用户重定向到“安全”页面之外

<?php
//...Valid user check
if(!$validuser)
{
    header("Location: /");
    exit;
}
<?php header("Status: 404 Not Found"); ?>

Put this after session verification, the page with give 404 page error saying page not found 进行会话验证后,将其显示为404页面错误,提示页面未找到

For example you can put it in 例如,您可以将其放入

if(!$user_loggedin) {
header("Status: 404 Not Found");
} else {

echo "welcome to your page ....";


}

The above code will generate PAGE NOT FOUND ERROR if the user is not loged in. Which means, anyone seeying that error will thik the page does not exist at all 如果用户未登录,上面的代码将生成PAGE NOT FOUND ERROR。这意味着,任何看到该错误的人都会认为该页面根本不存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM