Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

include_once() stopped working in PHP5

Posted on 2007-11-18
17
Medium Priority
?
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +2
17 Comments
 
LVL 143

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 143

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 2000 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 143

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 143

Expert Comment

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

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.

722 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