PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Warning: include(includes/test.php?var=test) [function.include]: failed to open stream: No such file or directory in [path]
Warning: include() [function.include]: Failed opening 'includes/test.php?var=test' for inclusion (include_path='.') in [path]
Please tell me I am doing something dumb. The issue has got rather confusing because the actual page I am trying to fix works on a server. We are moving to a new server and now all of a sudden only includes with querystrings are not working. With the code above I get no error (display_errors is on) and no echo. Initially I thought that allow_url_fopen must be off but I have checked and even used ini_set() to make sure it was on.
I am currently comparing ini settings from the two servers to see if anything else comes up. The site is being hosted and the hosting company swear that everything is ok.
You seem to be confused by how including and remote including work.
Unless test.php returns php code (which I doubt is the case), it is wrong for you to include it in that way (you need to use a full url, http://.. etc)
Most probably you want to include test.php and pass it some variables. There are several ways to do that, with increasing level of okay-ness:
1. Hacky:
Thanks alot! That works great. I still have a problem however as the site we are moving over to a new server is proliferated with querystring includes such as include(test.php?var=1). They simply don't work on the new server. It seems to be interpreting includes as local file paths rather than URLs. allow_url_fopen is set to on.
We are taking this site over from another company and hundreds of pages use this form of include. Is there any setting that you have to turn on to allow this? It is rather frustrating that it works on the old server and not on the new one.
Testing on at home I can get the includes to work when allow_url_include is set to 'on'. I have to edit the php.ini file for this. Trying to do it with ini_set is not currently working. I doubt the hosting company will edit their php.ini file just for us! I really don't want to have to start editing all this include statements to use global variables but I might have to.
allow_url_fopen isn't involved with include() unless it's a remote request. The act of having a query string isn't remote to PHP. There's something else between things.
feyd:~ feyd$ php -v
PHP 5.2.3 (cli) (built: Jul 26 2007 17:14:09)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
feyd:~ feyd$ php -d allow_url_include=1 -d allow_url_fopen=1 -r "var_dump(ini_get('allow_url_fopen'),ini_get('allow_url_fopen')); include 'test.php?var=crazy';"
string(1) "1"
string(1) "1"
PHP Warning: include(test.php?var=crazy): failed to open stream: No such file or directory in Command line code on line 1
<span style=color:red>
Warning: include(test.php?var=crazy): failed to open stream: No such file or directory in Command line code on line 1
</span>PHP Warning: include(): Failed opening 'test.php?var=crazy' for inclusion (include_path='.:/opt/local/lib/php') in Command line code on line 1
<span style=color:red>
Warning: include(): Failed opening 'test.php?var=crazy' for inclusion (include_path='.:/opt/local/lib/php') in Command line code on line 1
feyd:~ feyd$ cat test.php
<?php
echo $_GET['var'];
Thanks for everyones help! I can include("test.php?var=1") to work when allow_url_fopen and allow_url_include are both set to 1. Seems the old site was using PHP 4 which did not have allow_url_include.
I tested this at home. Now all I have to do is see if I can get this set on the hosting server. Might have to try setting this in the .htaccess file or trying to use a local php.ini file because ini_set is not working. Not sure if the hosting company have allow_url_include off for security purposes. Obviously now that I have looked into it I would rather not use querystrings but this is how it was originally coded and I would rather not have to trudge through all the files. I will post how it goes tomorrow. Again many thanks.