I am trying to include a file from a url, however I get the following error thrown up.
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58
Warning: include(http://localhost/diningtime/templates/100/index.php): failed to open stream: no suitable wrapper could be found in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58
Warning: include(): Failed opening 'http://localhost/diningtime/templates/100/index.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.4.4/lib/php') in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58
Test
Just wondering if there is anyway around this?
My PHP include code is
<?php include "$location/index.php"; ?>
I appreciate your help on this.
You're using a full URL as you include path, which tells PHP to attempt to do an HTTP request to fetch that file. This is NOT how you do this. Unless that ...100/index.php outputs PHP code, you are going to get some HTML or whatever as the include result, NOT the php code in the file. Remember - you're fetching via URL, which means it's an HTTP request, which means the webserver will EXECUTE that script and deliver its output, not simply serve up its source code.
There's no way for the webserver to tell that the HTTP request for that script is an include call from another PHP script on the same server. It could just as easily be a request for that script from some hacker hiding in Russia wanting to steal your source code. Do you want your source code visible to the world like this?
For local files, you should never use a full-blown url. it's hideously inefficient, and will no do what you want. why not simply have
include('/path/to/templates/100/index.php');
instead, which will be a local file-only request, with no HTTP stage included?
I have had a similar issue.
Considering 'Marc B's' post, it is clear that using absolute URLs is not a great idea, even if it is possible by editing the php.ini as 'ficuscr' states. I'm not sure this workaround will work for your specific situation as it still requires adjustments to each page depending on where it is in your folder structure, but it does makes things simpler if, like me, you have a lot of includes in your website.
<?php $root="../";?>
<?php include($root . 'folder-A/file_to_be_included_1.php');?>
<?php include($root . 'folder-A/file_to_be_included_2.php');?>
<?php include($root . 'folder-B/file_to_be_included_3.php');?>
<?php include($root . 'folder-B/file_to_be_included_4.php');?>
<?php include($root . 'folder-B/sub-folder/file_to_be_included_5.php');?>
For me, this means if I move a page to another location in the folder structure, for example in a sub-folder of its current location, all I need to do is amend <?php $root="../";?> to become <?php $root="../../";?> for example
Related
I try to include PHP file from different places of my computer. So I have defined different include paths in my php.ini
include_path=".;C:\project\a;X:\project\b"
When I try to include a file X:\project\b\file_b.php from a PHP script on C:\project\a\file_a.php with
require_once("file_b.php");
or with
require_once("X:\project\b\file_b.php");
I get the error
Warning: require_once(X:\project\b\file_b.php): failed to open stream: No such file or directory in C:\project\a\file_a.php on line 2
Fatal error: require_once(): Failed opening required 'X:\project\b\file_b.php' (include_path='.;C:\project\a;X:\project\b') in C:\project\a\file_a.php on line 2
Abort Processing during Fatal-Error: require_once(): Failed opening required 'X:\project\b\file_b.php' (include_path='.;C:\project\a;X:\project\b') Error in Script C:\project\a\file_a.php on Line 2
I have tried everything I can do with my knowlegde, but nothing works.
I hope, that someone can hlep me with solving this problem. Is there a problem with include paths on different drives on a Windows system?
Best regards,
bition
After a long time, I have finally the answer for my special problem.
It is really ery special, because I use BoxCryptor to encrypt my D: drive. BoxCryptor creates the virtual device X:, but it is not present for Apache and PHP. But I can configure BoxCryptor the mount the device X: as a rwal harddrive. After I set this, everythings works fine.
Sorry for the confusion about my vortual and real harddrives and thank you for your help!
Best regards,
bition
I have found with WAMP etc in the past, that using backslashs works. Just dont encapsulate the string with double quotes "C:\path", this will process the contents as #Marc B warns. Instead encapsulate the string with single quotes 'C:\path' and then the contents are not processed.
If the backslashes in the contents of the single quote string are still being processed, try the following.
<?php
$path = 'X:/project/b/file_b.php'; // PATH WITH FORWARD SLASHS
$path = str_replace(chr(47) ,chr(92) ,$path); // REPLACE FORWARD WITH BACKWARD SLASHS
require_once($path); // RUN FILE
?>
I have what should be a fairly straightforward operation, which gives me an error that doesn't seem very helpful. The code is this:
<?php
$strLines = file('//tardis/htdocs/apps/freespace/FreeSpace-Servers.txt');
.
.
.
?>
But in php-errors.log, I get this:
[28-Aug-2013 16:31:30] PHP Warning: file(//tardis/htdocs/apps/freespace/FreeSpace-Servers.txt) [function.file]: failed to open stream: Invalid argument in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\apps\freespace\freespace.php on line 2
The txt file is definitely there. Any ideas what else an "Invalid argument" might suggest? The documentation doesn't seem to hint at much of anything else. Or, should I be doing this a different way? My goal is to read the file in as an array of things. All help is appreciated.
If you're using UNC, then the address should be
file('\\\\tardis\\htdocs\\apps\\freespace\\FreeSpace-Servers.txt');
You may also need to check that your PHP configuration allows you to open remote files.
I have a somewhat more correct answer than any of the above. While all of the above is completely right, the actual problem (and solution) is detailed on question 18748985: PHP fails to read files.
The short answer is: The Apache user password was changed, but Apache didn't know about it. Update the password and restart the service. The overall problem is slightly more colorful than that, but that's how the issue is most succinctly reduced.
Background
I am trying to include an rss feed using php into a html document
Code
<?php
include ("feed url");
?>
I have used ssl command to successfully add the include tag in the html file like this
<!--#include virtual="rssfeed.php" -->
which works fine after editing htaccess file. Now problem is because in my php im using include ("feed url") I am getting this error:
Warning: include() [function.include]: URL file-access is disabled in
the server configuration in path/rssfeed.php on line 2
Warning: include(feed url) [function.include]: failed to open stream:
no suitable wrapper could be found in path/rssfeed.php on line 2
Now things to note I have tried setting php_value allow_url_fopen 1 but no luck as the files are held on third party hosting server so I do not have alot of access so they have blocked me from turning allow_url_fopen to ON for obvious reasons. So My question is how do I approch this problem ? Any directions will be greatly apperciated.
Thanks everyone for reading.
Your server is configured in such a way that you cannot include from a remote location. This is common in shared hosting environments to help reduce server load and reduce the possibility of malicious code being accidentally executed.
However, if I understand you right, you could not just include the RSS feed using the include() construct anyway, because it is not valid PHP code - include() expects the path to be a valid PHP source code file. What you are doing, if your server allowed you to do it, would result in either useless output or a parse error.
You need to connect to the RSS feed (e.g. using cURL or fsockopen() depending on the level of control you want over the request to the remote site) and parse the feed data so you can output in a sensible format.
include "http://..." is a bad idea because the contents of http://... are evaluated as PHP code which opens your site open to attacks if someone can inject PHP code in the response of that RSS feed.
Use curl if you want to display data from another site. From the PHP Manual example:
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
I am running the code below in some if/else statements, I have a weird issue in the same file this exact code below works fine, however in another area if it is called I get this error;
Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\webserver\htdocs\processing\process.friends.php on line 168
Warning: include(http://localhost/index.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\webserver\htdocs\processing\process.friends.php on line 168
$_SESSION['sess_msg'] = 'Please Enter the Correct Security Code';
$_GET["friendid"] = $friendid;
$_GET["p"] = 'mail.captcha';
$_GET["f"] = 'friend';
include ("index.php");
exit;
And just to clarify I am njot trying to run this code 2 times at the SAME time, it's more like this; Not just like this but you get the point that they are not run at the same time
if(something){
run the code above
}else{
run the code above
}
If it matters, I am currently running a LAMP setup on a windows PC
remove the "http://localhost" part of your code. As a rule of thumb, when you include your own files, you should include them from your file system.
include "./index.php";
Just remove the http://localhost/ part and you'll be okay.
Well, I don't kow the answer to your question, though I do have to ask why you feel the need to include a URL based file?
include('http://whatever.com/'); can be EXTREMELY dangerous.
If you're just trying to output the HTML generated from that, I'd suggest you do something like echo file_get_contents('http://some/url');. If you're trying to include PHP code, use the system path
Are they EXACTLY the same? Could you post both versions of the code?
I can also recommend not doing an include('http://...'); This will make PHP to an HTTP request to your webserver, and grab the result. You might be a bit better off just doing include('index.php');, if this is possible for your setup.
Is allow_url_fopen enabled in php.ini?
I'm debugging some PHP code written by an outsourcing company (I'm not a PHP guy at all but know the basics; we have an offshore team of PHP developers working for us on this project) that's not working; the code is supposed to be called every 30 minutes by a cron job but its not firing. I tried to run the PHP script via the command line to test if it's working, but it's giving me the following (anonymized) errror:
PHP Fatal error: require_once(): Failed opening required '/myapp/_lib/_classes/MySql.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/myapp/_lib/_base/common.inc.php on line 6
However, the file /var/www/html/myapp/_lib/_classes/MySql.php exists under the proper directory. I'm missing something simple, I'm sure, but like I said I know really nothing beyond the bare basics of PHP and I really need to get this service up and running.
EDIT: The code is using the __autoload() function with all classes in /_lib/_classes
if you start a file name with a slash, it means it's an absolute path. try instead:
require_once('/var/www/html/myapp/_lib/_classes/MySql.php');
Case sensitivity maybe? I've had that problem before.
I'm guessing it's a permissions issue - make sure both your account (for testing purposes) and whatever account cron is going to run your script under (quite possibly yours, but maybe a different one) have read privileges on the file.
Also: the path for the include says /myapp/_lib/_classes/MySql.php, whereas it exists in /var/www/html/myapp/_lib/_classes/MySql.php. Can you change the include to reference the full path?
As said, casing and in addition the correct permissions to access that file are needed.