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?
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.
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
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.
I am currently using an image manipulation script to do some work on uploaded images and I'm running into a problem in my dev environment. This same code works on my production server.
The error is:
PHP Warning: imagecreatefromjpeg(): php_network_getaddresses:
getaddrinfo failed: Name or service not known in /path/to/script.php
on line 75
The line of code on 75 is:
$this->img = imagecreatefromjpeg(PHPTHUMB."?src=/".$this->image_path);
which creates an image that is loaded from another made by phpThumb, which is used for further manipulation.
Any ideas on how to solve this? Can anyone shed some light on what the error means?
Thank you,
Edit:
Just as a further bit of insight, if i visit PHPTHUMB . "?src=/" . $this->image_path in my browser, the image loads fine
User agent in php.ini did not solve the problem as indicated here
EDIT (SOLUTION): I had to add the INTERNAL 192.168.204.XXX IP into the hosts file, so that http://dev.mysite.com resolved correctly. Trying both 127.0.0.1 and the external IP yielded no result, but the internal works perfectly. Thanks for everyone's efforts,
I'm totally not sure about the cause of that error, but this is my best guess.
There is a particular PHP Setting which enables you to treat URLs as files. Normally imagecreatefromjpeg accepts a filename, I think. Since you are passing a URL, you need to make sure the particular setting is enabled. I believe you can find more info about it here: http://us2.php.net/file
filename
Path to the file.
Tip
A URL can be used as a filename with this function if the fopen
wrappers have been enabled. See
fopen() for more details on how to
specify the filename and List of
Supported Protocols/Wrappers for a
list of supported URL protocols.
Fopen wrappers: http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen
Your dev environment may not be setup with this, but your production environment could be.
Edit
This page lists your error:
http://bugs.php.net/bug.php?id=11058
and mentions that a possible fix is by modifying your hosts file to explicitly include the ip/dns of the server you're accessing.
i tryed to reconfigure my named
configuration, without any result, to
fix this. the problem was solved by
adding the following line to my
/etc/hosts:
194.97.55.147 mx.freenet.de
Maybe you can try this?
did you also check that allow_url_fopen is set to On in php.ini?
I saw that they did mention that in the article you referred to in your post.
EDIT: Also, what OS and what PHP version are you running?
Just read this on php.net: "On Windows versions prior to PHP 4.3.0, the following functions do not support remote file accessing: include(), include_once(), require(), require_once() and the imagecreatefromXXX functions in the GD Functions extension."
EDIT2:
I just read what was written in the comments, your allow_url_fopen is set to On, sorry about that.
But OS, PHP version and phpinfo() would help in finding the problem.
The error message suggests something is wrong at a networking level. Thus, if possible, bypass that. Try using the path to the thumbnail generator, instead of a network address.
If that's not an option, try something that will give you more granular error messages. I suggest CURL. At the very least, it should yield a more informative error message.
The simple fact that this is failing is because on your webserver, your DNS resolution is broken.
If you have SSH access to your server, try the following command
dig hostname
where hostname is the host name from PHPTHUMB
This will probably fail.
Assuming that you're using Linux, my suggestion would be to edit your /etc/resolv.conf (as root)
and add the following line before any other lines beginning with "nameserver"
nameserver 4.2.2.2
This should hopefully fix things, though you may have to restart apache (or whatever webserver you're using)!
The issue here is that php fails to resolve the url that you provide as PHPTHUMB as stated in this bug report on php.net. This possibly means that it's the fault of the operating system/web server, in which case you can enter the ip address of the server you are connecting to into your hosts file manually.