gpt4 book ai didi

php - 禁止直接访问某个页面

转载 作者:行者123 更新时间:2023-11-29 07:29:06 26 4
gpt4 key购买 nike

如何创建无法通过直接url打开的页面?

我的index.php , main.phpconfig.php

我想创建 data.php 以从数据库表中获取一些结果。但 data.php 需要一些编码:1.确保安全(无直接访问)2.从sql数据库获取表

最佳答案

为了防止直接访问,您可以执行以下任一操作:

if(count(get_included_files()) ==1) exit("error");

debug_backtrace() || die ("error");

if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) die('Error');

The best way to prevent direct access to files is to place them outside of the web-server document root (usually, one level above). You can still include them, but there is no possibility of someone accessing them through an http request.

另一种方式,拒绝扩展名匹配:

<FilesMatch "\.(inc)$">

Order deny,allow
Deny from all
<FilesMatch>

关于php - 禁止直接访问某个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33384039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com