INCLUDE_CHECK 在 php 中做什么?
你好,我是 php 新手,当我遇到 Define('INCLUDE_CHECK',true); 时我无法理解它的用途是什么?
请。解释。
谢谢! 萨加尔
Hi I am new in php and when I came across define('INCLUDE_CHECK',true); I was not able to understand what it is for?
Pls. explain.
Thanks!
Sagar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是该应用程序稍后将使用的常量。 Define() 用于创建这些常量。通常这用于配置数据。要稍后使用此常量,您只需在代码中使用字符串 INCLUDE_CHECK ,就像它是一个不带 $ 的变量一样。
所以
This is a constant that is being used by that application later. Define() is used to create these constants. Typically this is used for configuration data. To use this constant later, you simply use the string INCLUDE_CHECK in code like it were a variable without the $.
so
只是对 DampeS8N 答案的补充,这是正确的。
我阅读了 php.net 的链接 https://www.php.net/manual/ en/function.define.php
下面的示例清楚地表明,可以在定义函数内部使用任何值来将变量定义为常量,并且 INCLUDE_CHECK 只是一个变量,我认为它是某种 php 功能;)
@DampeS8N 请。如有错误请评论!
感谢大家的回答!
Just an addition to DampeS8N Answer which is correct one.
I read php.net's link https://www.php.net/manual/en/function.define.php
and below example makes it clear that any value can be used inside define function for defining variable as constant and INCLUDE_CHECK was just a variable which I thought as some kind of php feature ;)
@DampeS8N pls. comment if wrong!
Thanks to all of you for your answers!
INCLUDE_CHECK 不是 PHP 本身的特性,只是某人用 PHP 编写的一些代码的特性。 Google 上的第一个点击向我们展示了用户试图通过检查变量是否已定义来保护的配置文件。
我在谷歌上找到的狙击中采取的方法就像这样
以下示例应该使这一点更清楚
foo.php
config.php
如果用户直接访问 config.php,则未定义 INCLUDE_CHECK,因此脚本将因无效访问消息而终止。如果用户访问 foo.php,它将定义 INCLUDE_CHECK 然后包含 config.php,然后它将回显 Hello World。
顺便说一句,这是一种非常糟糕的保护配置文件的方法;请参阅我的帖子以获得更简单、更可靠的方法。
INCLUDE_CHECK is not a feature of PHP itself, only of some code that someone has written in PHP. The first hit on google shows us a configuration file that a user is attempting to protect by checking if the variable is defined.
The approach taken in the sniped I found on google is like this
The following examples should make this clearer
foo.php
config.php
If a user accesses config.php directly, then INCLUDE_CHECK is not defined, so the script will die with the message invalid access. If a user accesses foo.php, it will define INCLUDE_CHECK then include config.php, which will then echo Hello World.
This is a pretty crap way of protecting a configuration file, btw; see my post here for a more simple and reliable approach.