0

I have a smarty project:

in the devidate_server.php:

<?php

include($_SERVER['DOCUMENT_ROOT'] . '/ax/ax_conf/CONSTANTS.php');
include($_SERVER['DOCUMENT_ROOT'] . '/ax/utils/utils.php');
...

there I will get error, but I can not get the error information, because I am develop WHMCS, I don't know the traceback's place. Give me information is the interface is blank.

But if I comment the include($_SERVER['DOCUMENT_ROOT'] . '/ax/utils/utils.php'); there will not get error.

There will shows the interface content.

in the utils.php there is:

<?php

include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/utils/http_util.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/qi_cloud_config/urls.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/libs/Requests/library/Requests.php');
Requests::register_autoloader();

function fetch_qicloud_access_tokens($params){

    $result = Requests::post('http://localhost:8000/o/token', [
        // headers
    'Accept'=>'application/json'
 ], $params, [
        // options
        'auth' => new Requests_Auth_Basic([QICLOUD_whmcs_pj_client_id, QICLOUD_whmcs_pj_client_secret])
    ]);

    return $result;
}

I don't know why I get include error, who can help me why I comment that line there will be normal?


EDIT-01

I get the error log:

[Wed Jul 18 11:26:52.040872 2018] [proxy_fcgi:error] [pid 29189:tid 139662983087872] [client 118.113.136.133:29440] AH01071: Got error 'PHP message: PHP Warning: require(/usr/local/httpd/htdocs/whmcs/qi_cloud/libs/Requests/library/Requests.php): failed to open stream: No such file or directory in /usr/local/httpd/htdocs/whmcs/qi_cloud/utils/http_util.php on line 9\nPHP message: PHP Warning: require(/usr/local/httpd/htdocs/whmcs/qi_cloud/libs/Requests/library/Requests.php): failed to open stream: No such file or directory in /usr/local/httpd/htdocs/whmcs/qi_cloud/utils/http_util.php on line 9\nPHP message: PHP Fatal error: require(): Failed opening required '/usr/local/httpd/htdocs/whmcs/qi_cloud/libs/Requests/library/Requests.php' (include_path='.:/usr/share/pear:/usr/share/php') in /usr/local/httpd/htdocs/whmcs/qi_cloud/utils/http_util.php on line 9\n', referer: http://www.example.net/clientarea.php


EDIT-2

the qi_cloud/utils/utils.php

<?php

include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/utils/http_util.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/qi_cloud_config/urls.php');
include($_SERVER['DOCUMENT_ROOT'].'/qi_cloud/libs/Requests/library/Requests.php');
Requests::register_autoloader();
...

the urls.php

<?php

require('./CONSTANTS.php');

define('qicloud_oauth_token_url', QICLOUD_BASE_API . 'o/token/'); // 

the CONSTANTS.php:

<?php

define('QICLOUD_BASE_API', 'http://103.200.32.76:8000/');   
...
sof-03
  • 2,255
  • 4
  • 15
  • 33

1 Answers1

0

You should not rely on documents root.

Do something like:

require_once(DIR . '/relative/path/from/current/directory/file.php');

The require once will stop execute ifbfile is not there since it's require. The once will make sure you don't include the file twice if you pass by this code a second time. You should never include a file that as finction/class/constant declaration more than one. And if you use a proper IDE (like phpstorm) you will have a warning if the file path is invalid. This cannot be achieved with the document root variable.

But I don't know your exact contalext but you should check something like composer.json to handle your dependencies.

P.s. there is 2 underscore before and after the DIR magic constant but formatting on the mobile web version is limited and force bold...

  • I believe the problem here was not the usage of DOCUMENT_ROOT but the usage of relative paths induce the included files. –  Jul 18 '18 at 12:23