Failed to open stream error : Http request failed - 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)

Related

If I include a file, I will get Include error

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...

PHP unable to open include file

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.

Permission denied on codeigniter

I'm running an Apache server on my PC with Debian 7 (well, actually Crunchbang, but it's the same thing).
I was playing with the CodeIgniter framework, and it was working all right. I completed the first tutorial, the one in which you create your first static page (this one: http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html ), and it worked perfectly.
However, as you can see on the very first step, there's a line that goes like this:
[...]
public function view($page = 'home')
[...]
I changed that line to " $page = 'about' ", to try if it could display the other page instead. That's when Hell opened its doors and released the Kraken.
Then it started to show a 404 error, so I changed the settings back again, but the error kept ocurring. I restarted Apache, restarted my PC (I don't know, sometimes it works) and finally, deleted the codeigniter files from my /var/www/ directory, and copied them again.
Now the error is different: It just displays nothing! A blank page, just that. This is what my apache errorlog says:
[Fri Feb 21 23:03:11 2014] [error] [client 127.0.0.1] PHP Warning: require_once(/var/www/system/core/CodeIgniter.php): failed to open stream: Permission denied in /var/www/index.php on line 202
[Fri Feb 21 23:03:11 2014] [error] [client 127.0.0.1] PHP Fatal error: require_once(): Failed opening required '/var/www/system/core/CodeIgniter.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/index.php on line 202
It sounds like the permissions are set incorrectly on your server.
Check what group Apache runs in (I think Debian by default uses www-data), and make sure you set the group owner and read permissions.
# chown www-data:www-data -R /var/www
# chmod g+r -R /var/www
If the above doesn't work, try setting permissions to 777 just to see if the problem lies elsewhere. I couldn't imagine what else could cause that error, though.

how can I know what is the necessary permission for my new codeigniter project?

I just installed apache2 and php5 on my ubuntu computer, Ive done it before on debian but now I have a weird error.
when I try to reach a page with my framework in CodeIgniter I get this error
[error] [client 127.0.0.1] PHP Warning: require_once(/var/www/project/system/core/CodeIgniter.php): failed to open stream: Permission denied in /var/www/project/index.php on line 202, referer: localhost/
[error] [client 127.0.0.1] PHP Fatal error: require_once(): Failed opening required '/var/www/project/system/core/CodeIgniter.php' (include_path='.:/usr/share/php5-common') in /var/www/project/index.php on line 202, referer: localhost/
before that I have an error of not found on my include_path, so , I changed it on my php.ini and i changed it to :/usr/share/php5-common
Still... I have NO idea what is the error...
I changed permissions on my /var/www folder and its like user:user
on the line of index.php I have this:
require_once BASEPATH.'core/CodeIgniter.php';
Most probably your $config['base_url'] is wrong.
Make sure its properly identifies the localhost or IP you are using to access localhost.
I mean if you are accessing local server or remote server using http://[ipaddress] then you have to define baseurl like that only.
in your case may be **$config['base_url'] = http://127.0.0.1/codeigniter_project_name**
Similarly that applies to database config also.

I can't run the Phpass tests

Anyone know exaclty what's going wrong, I'm running Ubuntu (server) and have apache 2.2.14-5 and php 5.3.2-1 installed. When accessing the test.php file I get a HTTP 500 error. Here's what I get in my error.log
[Thu Oct 27 16:15:41 2011] [error] [client myip] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
[Thu Oct 27 16:15:41 2011] [error] [client myip] PHP Fatal error: Unknown: Failed opening required '/blob/public_html/phpass-0.3/test.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0
Anyone know how to setup PHPass?
EDIT: Made a much simpler test: http://pastebin.com/TWq3C9Km, produced the same errors as above.
EDIT2: I have narrowed down what causes these errors to the following lines of code:
if(is_readable('/dev/urandom') && ($fh = #fopen('/dev/urandom', 'rb'))) {
$output = fread($fh, $count);
fclose($fh);
}
EDIT3: Turns out I can't read error messages, whats actually happening is PHP can't read the file itself. A quick sudo chmod -R 777 phpass-0.3 temporarily fixes that, but here must be a better way.
That error message usually indicates file permission problems as already pointed out. Global read/write/execute permissions are certainly not required, but make sure to give Apache read access to the files. For example:
chmod 755 phpass-0.3
chmod 644 phpass-0.3/*.php

Categories