Solved

include_once() stopped working in PHP5

Posted on 2007-11-18
17
431 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

16 Experts available now in Live!

Get 1:1 Help Now