Questions about using define in include

Source: Internet
Author: User
Questions about using define in include
a.php

Define (' PATH ', DirName (__file__));
Include ('./index.php ');
.
.
.
?>


b.php

Include (.. /a.php);
Echo PATH;

Where a.php and index.php are in the same folder, and b.php in A.php's parent folder.
Run the above b.php, the result is wrong, say include () function fial to open index.php, and then output path, and paht value when the absolute path of a.php.
This is what is the case, if the include function of the mechanism is to include the file does not do any processing is included in, then the value of path should be b.php absolute path, if the include function is to be included in the first processing of some functions, then include ('./ index.php '); ask what does not execute? What is the working mechanism of include and define? Seek the Master
------Optimal Solution--------------------
What does include have to do with define, is there index.php in the current directory of a.php?

2. Your constant path is defined in a.php and takes the absolute path of a.php
------Other Solutions--------------------
Use include (' index.php '); Give it a try
------Other Solutions--------------------
Reference:
use the Include (' index.php ');//
try

A.php and index.php in the same folder, and then I changed to include (' index.php ') on it, which is why?
' .' Does not mean that the current road strength, './index.php ' and ' index.php ' are not the same?
And what is the working mechanism of include?
------Other Solutions--------------------
"Summary of solutions to include paths in PHP" This blog post seems to solve my problem. The original problem appears in __file__ here, the article mentions "__file__ always equals to the real path of a PHP script regardless whether it ' s included." __file__ is always the same as the path to the file that uses it, regardless of whether the file is contained. That's why I'm talking about things. It also shows that the include path is a dangerous issue!!!!!
------Other Solutions--------------------
When you visit a.php is relative to a.php, so./index.php and index.php are all right, but if you visit b.php, it should be relative to b.php at this time, so./index.php is wrong. /index.php or index.php, that's what I understand.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.