search
Homephp教程php手册动态网页中直接不让访问PHP程序文件

由于我们有需要用到某些php文件,而又不希望别人直接访问这个文件,我们可以在其他包含文件比如global.php中定义一个参数,在被访问页面data.php前面判断是否定义了该参数,没有定义则禁止访问。

在global.php中定义

以下为引用的内容:

define('ROOT','./');
?>
在data.php文件中判断:


//data.php
if (!defined("ROOT")) {
 echo "You Cannot Access This Script Directly, Have a Nice Day.";
 exit();
}
?>

这样的代码可以解决很多的安全问题,比如变量未定义[应该说在本文件内未定义]。

但是这样的在本地包含漏洞前就没什么意义了。比如进来看一代码

common.php文件里:

以下为引用的内容:

if ( !defined('ROOT') )
{
 die('Do not access this file directly.');
}
if ( !isset($root_path) )
{
 $root_path = './';
}
require_once($root_path . 'config.php');
?>

如果没有!defined('X') 的限制,那么这里$root_path未定义导致了一个远程包含。

而在改脚本又存在一个update-->include的2次攻击导致的本地包含,那么我们可以通过这个本地包含漏洞包含common.php导致突破!defined('X'),转化为远程包含。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)