Solved

include_once() stopped working in PHP5

Posted on 2007-11-18
17
442 Views
Last Modified: 2013-12-13
I just noticed my website shows only white page, I have the following php code the link functions


<?php
// Links functions for all pages
$go = $_GET['go'];

switch ($go) {

  case 'sitemap' : include_once 'http://localhost/info.php';
  break;
  case 'help' : include_once 'http://localhost/contactus.php';
  break;
  case 'beta' : include_once 'http://localhost/beta.php';
  break;
  case '' : include "http://localhost/index.htm";
  break;

}
     
?>

I just upgraded my PHP to version 5 and it was working on version 4.
I didn't get any error, threrfore I installed XAMPP on my computer to see if the problem from my server or the code I have,
and the good thing in XAMPP is I can switch between PHP 4 and 5 with one click, so on PHP 4 it worked fine but on PHP5 I get the following error:


Warning: include() [function.include]: URL file-access is disabled in the server configuration in D:\xampp\htdocs\index.php on line 62

Warning: include(http://localhost/index.htm) [function.include]: failed to open stream: no suitable wrapper could be found in D:\xampp\htdocs\index.php on line 62

Warning: include() [function.include]: Failed opening 'http://localhost/index.htm' for inclusion (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\index.php on line 62

I checked Experts Exchange and Google for a solution for this error and the only thing I got from php.net is I have to enable allow_url_include in php.ini
but I done that and nothing changed still getting that same error message.!!
anyone got accross the problem before? could help me out.

Thank you,
0
Comment
Question by:maxnca
  • 5
  • 4
  • 4
  • +2
17 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20310474
include_once, by default in php5, does not allow http references:
Warning: include() [function.include]: URL file-access is disabled in the server configuration

>the only thing I got from php.net is I have to enable allow_url_include in php.ini
yes, that is correct.
now, did you modify the correct php.ini? by default, it is the one in windows folder...
please clarify
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20310494
as angellll said, its a permission problem to do with URL include http://....

Where is your script located? if it is located in the root directory of localhost why not try below:
<?php  		  	
// Links functions for all pages
$go = $_GET['go'];
 
switch ($go) {
  case 'sitemap' : 
  include_once('info.php');
  break;
  case 'help' : 
  include_once('contactus.php');
  break;
  case 'beta' : 
  include_once('beta.php');
  break;
  case '' : 
  include("index.htm");
  break;
 
}
     
?>

Open in new window

0
 
LVL 1

Author Comment

by:maxnca
ID: 20310518
angelll: yes i edited the corrected php.ini because XAMPP has only one php.ini file in its php folder.

nizsmo: it is the root directory, and I tried the modifide codes you  posted but got the same error.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20310532
if with the modified code you get the same error, it must be some other place in the code that actually raises the problem?
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20310538
can you try require('file.html") and see if it gives the same error?
0
 
LVL 1

Author Comment

by:maxnca
ID: 20310564
I tried require() and gave me the same error.!
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20310582
please copy and paste the error? EXACTLY the same? or slightly different?
0
 
LVL 1

Author Comment

by:maxnca
ID: 20310596

Warning: require() [function.require]: URL file-access is disabled in the server configuration in D:\xampp\htdocs\index.php on line 62

Warning: require(http://localhost/index.htm) [function.require]: failed to open stream: no suitable wrapper could be found in D:\xampp\htdocs\index.php on line 62

Fatal error: require() [function.require]: Failed opening required 'http://localhost/index.htm' (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\index.php on line 62
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20310673
As angelIII said above allow_url_include needs to be on.

make a new file and put in the following code

<? phpinfo(); ?>

and check if allow_url_include is set to on.

Check also the path to the php.ini to make sure you are editing the correct one.

For any changes in php.ini to take effect you need to restart the server.
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20310713
try the require without the http://? it is best to include/require your files without the http:// anyway as then the path is relative and only has to be in the same directory as the script. otherwise in the future when you upload your script to another server you will encounter problems with these include/require paths.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 20310834
Can you try and change your code to:

  case 'sitemap' : include_once 'info.php';
  break;
  case 'help' : include_once 'contactus.php';
  break;
  case 'beta' : include_once 'beta.php';
  break;
  case '' : readfile("index.htm");
  break;

As mentioned, it is inefficient en unnecessairy to use include_once 'http://localhost/....'

Kind regards

-r-
0
 
LVL 1

Author Comment

by:maxnca
ID: 20311358
ok, I tried everything you said and nothing changed,!!
but what I noticed the line allow_url_include is not showing in the PHP info page, even when i went to the file I see it set to "on" and I used the same php.ini file to edit that is listed under Configuration File (php.ini) Path : /usr/local/Zend/etc/php.ini  and restarted apache couple of time but is not showing up !!!
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20311413
then, let me repeat: check if you have a php.ini file in the windows folder.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 20311421
@angelIII

He's probably running on linux, as his php.ini path is at /usr/local/Zend/etc/php.ini

@maxnca,

Can you check if there is a php.ini at /etc/php.ini ?

-r-
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20311446
Ok something is wrong here ....


Warning: require(http://localhost/index.htm) [function.require]: failed to open stream: no suitable wrapper could be found in D:\xampp\htdocs\index.php on line 62

 D:\xampp\htdocs\index.php === Windows machine

Path : /usr/local/Zend/etc/php.ini === *inx

???
0
 
LVL 1

Author Comment

by:maxnca
ID: 20311450
Sorry let me clear things up I'm running the file on both windows and linux on windows it is working fine now after adding the allow_url_include inside the php.ini
but in linux still not working even I added it in php.ini,

Roonaan: there is no php.ini in /etc
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20311456
I agree with steelseth12... something is wrong ...
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now