The PHP require_once () function introduces a workaround for files not found

Source: Internet
Author: User


Today with PHP to write a simple Android login server code, encountered a particularly depressing thing, using require_once () introduced to the PHP file in the file error message, the file is not found.

PHP require_once () is mainly used to introduce a PHP file into another php file, I first talk about the problems I encountered, my directory structure is this:

That's what I wrote in user.class.php :

Require_once (".. /config/mysqlconfig.php "); require_once ('.. /util/handlemysql.class.php ');

It looks really good, but I've introduced user.class.php in the index.php .

Require_once ("class/user.class.php");

The code looks good, however, the following error is reported in the run:

Think about it and finally found the problem:
The require_once () function actually puts the code of the file you include in the location you refer to, that is, after the above two references, in fact, in the index.php file now.

Require_once (".. /config/mysqlconfig.php "); require_once ('.. /util/handlemysql.class.php ');

Then index.php and follow this path to find the two files, nature will not find.
It seems that the relative path should be used cautiously in the actual development.

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.