include_once, relative path in php

前端 未结 5 807
-上瘾入骨i
-上瘾入骨i 2021-01-18 02:36

I have 3 files: home, failed_attempt, login.

The file home and failed_attempt all refer to login file.

The annoying thing is that they throw a mistake saying

5条回答
  •  渐次进展
    2021-01-18 02:48

    Here are three possible solutions. The second are really just work-arounds that use absolute paths in a clever way.

    1: chdir into the correct directory

    
    

    Note that this will only work if your StoredProcedure folder is in the topmost directory of any files that might need to include the files it contains.

    2: Use absolute paths

    Now before you say this is not portable, it actually depends on how you implement it. Here's an example that works with Apache:

    
    

    Alternatively, again with apache, put the following in your .htaccess in the root directory:

    php_value auto_prepend_file /path/to/example.php
    

    Then in example.php:

    
    

    And finally in your files:

    
    

    3: Set PHP's include_path

    See the manual entry for the include_path directive. If you don't have access to php.ini, then this can be set in .htaccess, providing you are using Apache and PHP is not installed as CGI, like so:

    php_value include_path '/path/to/my/includes/folder:/path/to/another/includes/folder'
    

提交回复
热议问题