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/');
...
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...
Related
I have [root]/includes/helpdesk/pipe.php with this code:
#!/opt/cpanel/ea-php55/root/usr/bin/php
<?php
require_once("pipeprocess.php");
In the same location in pipeprocess.php in first line I include another file still in the same location: helpdesk.php
then in [root]/includes/helpdesk/helpdesk.php in the first line I have:
require_once ("../../config.php");
config.php is in [root], this is why I have twice ../../, helpdesk.php works fine with direct access, but if run pipe.php via pipe command setup in cPanel I get a bounce error that config. php is not found:
PHP Warning: require_once(../../config.php): failed to open stream:
No such file or directory in
/home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line
21
Warning: require_once(../../config.php): failed to open stream: No
such file or directory in
/home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on line
21 PHP Fatal error: require_once(): Failed opening required
'../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php')
in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on
line 21
Fatal error: require_once(): Failed opening required
'../../config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php')
in /home/[user]/public_html/[root]/includes/helpdesk/helpdesk.php on
line 21
Why I am getting this pipe error as direct access to helpdesk.php works fine? does pipe not accept ../ or ../../ as parth of the path? or is there an EasyApache4 issue? I did several tests and noticed this is because of ../ as part of including path. Does pipe/EasyApache4 have problem with this?
What if you used __DIR__, based on where your currently running script file's folder?
As of PHP 5.3.0, you could use something like this:
require_once (__DIR__ . "/../../config.php");
I now upload my project to server in digital ocean,but I get this error in apache2 error log
require_once(/var/www/html/example/v1../include/DbHandler.php): failed
to open stream: No such file or directory
The 2 line that occur error is this,is working well in localhost,but when go to server it having the error above
require_once '../include/DBHandler.php';
require_once '../include/PassHash.php';
My directory is as below,I have to required DBhandler.php which in include folder,and index.php is from v1 folder(the place that require_once calling from).
-include
-DBhandler.php
-PassHash.php
-v1
-index.php
Here is the error log I got
[Fri May 19 12:33:19.621030 2017] [:error] [pid 5236] [client 115.133.247.14:575 22] PHP Warning: require_once(/var/www/html/example/v1../include/ DbHandler.php): failed to open stream: No such file or directory in /var/www/htm l/example/v1/index.php on line 9
What I tried so far
require_once $_SERVER['DOCUMENT_ROOT'].'/include/DBHandler.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/include/PassHash.php';
And this,but none of this solve the problem
require_once __DIR__."/../include/DBHandler.php";
require_once __DIR__."/../include/PassHash.php";
Someone please help!Give me the a right direction,so I can proceed
Your require :
require_once '../include/DbHandler.php';
Your filename:
DBhandler.php
The name is different.
Change your require to:
require_once '../include/DBHandler.php';
May be your file name case: DBHandler intead of DbHandler
Just Remove the symbol / this on staring of file path your problem will be sovled.
require_once(var/www/html/example/v1../include/DbHandler.php): failed to open stream: No such file or directory
I have a problem with a PHP script. The following error is being logged whenever the site is accessed:
[Fri Sep 26 11:57:56 2014] [error] [client 31.22.44.2]
PHP Fatal error: require_once(): Failed opening required
'./sites/default/modules/views/handlers/views_handler_field_markup.inc'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc
on line 76
I have confirmed that the file referenced is present, and that www-data can access it. Permissions look fine and have not been changed as far as I am aware
What am I missing?
[Fri Sep 26 11:57:56 2014] [error] [client 31.22.44.2] PHP Fatal
error: require_once(): Failed opening required
'./sites/default/modules/views/handlers/views_handler_field_markup.inc'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc
on line 76
Add path /var/www/www.xoomtalk.com/htdocs into your include_path
More explains:
your include_path=.:/usr/share/php:/usr/share/pear , means php script will find include file in: current_path, /usr/share/php or /usr/share/pear
when you want to require this file
./sites/default/modules/views/handlers/views_handler_field_markup.inc
all allowed path are:
(current path)
/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/./sites/default/modules/views/handlers/views_handler_field_markup.inc
(/usr/share/php) /usr/share/php/./sites/default/modules/views/handlers/views_handler_field_markup.inc
(/usr/share/pear)
/usr/share/pear/sites/default/modules/views/handlers/views_handler_field_markup.inc
In these path ,php can't find the file.
in the following file:
/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/includes/handlers.inc
on line 76
Change This:
'./sites/default/modules/views/handlers/views_handler_field_markup.inc'
to THIS: '/var/www/www.xoomtalk.com/htdocs/sites/default/modules/views/handlers/views_handler_field_markup.inc'
This should do the trick.
The problem is, you're using scripts from various directories, but the "root" of the request is the cwd (current working directory) which you can check with: getcwd()
(and you're requesting the include relative to the cwd.
I managed to solve this problem, ended up being nothing to do with permissions or paths, although there was no indication of this in the Apache logs.
The problem was that the server was also running AppArmor which for some reason was blocking the Apache process from accessing the files.
AppArmor was set to complain rather than enforce mode for testing (command is aa-complain apache2) this made everything start working.
Thanks to all contributors for their suggestions.
I am starting to work on a site that has been up for some time. It is producing the following error messages before I even got started:
Warning: main(includes/main_functions.php) [function.main]: failed to open stream: No such file or directory in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 22
Warning: main() [function.include]: Failed opening 'includes/main_functions.php' for inclusion (include_path='.;c:\php\4\pear') in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 22
Warning: main(includes/functions/functions_email.php) [function.main]: failed to open stream: No such file or directory in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 23
Warning: main() [function.include]: Failed opening 'includes/functions/functions_email.php' for inclusion (include_path='.;c:\php\4\pear') in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 23
Fatal error: Call to undefined function: get_includes_file() in \\boswinfs01\home\users\web\b748\ez.paphospro\includes\top.php on line 24
Could it be that the path in the includes\top.php file is incorrect? Or do I need to look for something else?
the top.php file includes the following code:
define('BASE_PATH' , '/--/--/--/--/--/--/'); (I took out the path in this example).
and on the lines 22, 23, 24 it has the following code:
`include("includes/main_functions.php");
include("includes/functions/functions_email.php");
include(get_includes_file("includes/config.php"));`
all the above files are on the server in those directories.
I really need some direction as to why the errors are there and what I can do to fix them.
Thanks for any and all help or suggestions.
The warning is caused by non existing script file or wrong file permissions.
I would recommend you to do some refactoring, replacing the include function with require_once. This way you'll get a fatal E_COMPILE_ERROR level error which is better than a misleading application.
Then you must define your application base path define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR); and use it to reference all other application dependencies (e.g. require_once(DOCROOT.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'main_functions.php');
I have looked through all the threads on this forum, before posting this one. None of the solutions were able to solve my issues so I am forced to open a new thread.
I have the below include in my code but it errors out with "failed to open stream: HTTP request failed! " error. I already have this set in php.ini:
allow_url_include = On and
allow_url_fopen = On
but it still fails.
1.Below is the include defined in /test/foo.php which includes the file on the same server under /test/bar.php
<div class="tab-content" style=''>
<div class="tab-pane active" id="my1"><?php include('http://'. $_SERVER['SERVER_NAME'] . ':' .
$_SERVER['SERVER_PORT'] . "/bar.php?env=test1&days=3&start=$start&end=$end");?></div>
</div>
2.Here is the dir structure:
a) /test/foo.php --> this has include to my own server.
b) /test/bar.php
3.Apache document root is pointing to /test like
/var/www/html --> /test
4.echo __DIR__ shows me "/test" so its definitely pointing to the right directory.
5.I have given full permission to this directory in case that's the issue, but no luck.
6.Exact error in apache error log for one of the above includes. It doesn't for any of the above includes. Server Name and port are intentionally removed from below log.
[Sun Jul 07 15:01:47 2013] [error] [client ] PHP Warning: include(http://:/bar.php?env=my1&days=3&start=2013-06-07&end=2013-07-07): failed to open stream: HTTP request failed! in /test/foo.php on line 36
[Sun Jul 07 15:01:47 2013] [error] [client ] PHP Warning: include(): Failed opening 'http://:/bar.php?env=my1&days=3&start=2013-06-07&end=2013-07-07' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /test/foo.php on line 36
if
include('http://'. $_SERVER['SERVER_NAME'] . ':'
. $_SERVER['SERVER_PORT']
. "/bar.php?env=test1&days=3&start=$start&end=$end");
is trying to fetch from
http://:/bar.php?env=my1&days=3&start=2013-06-07&end=2013-07-07
It implies that $_SERVER['SERVER_NAME'] and $_SERVER['SERVER_PORT'] are blank. Are you running this from the command line?
(I assume you know that even with literal values you have created a big security hole in your system, that the resulting script will run massively slower than including the file directly, and that even if the variables were populated it doesn't mean that the routing / DNS on many hosts would allow you to access the code in this way)