Author Topic: PHP5 file-access is disabled...work around?  (Read 341 times)

0 Members and 1 Guest are viewing this topic.

Offline jamichelliTopic starter

  • Irregular
  • Posts: 25
    • View Profile
PHP5 file-access is disabled...work around?
« on: February 09, 2010, 09:42:02 PM »
I have a test page that I'm working on to figure out how to (supposedly) make my life a little easier.  I want to include or require a top row of menu buttons and another row of menu buttons on the bottom of my pages.  These page files will be located in subfolders with the php files to be included/required located in the root file.  In my research, I see that PHP5 has disabled absolute file access as a security measure.  Is there a work-around or code that I would be able to use so that I can simply get these buttons onto my pages and only have to update the 1 file should when it is needed instead of having to update every page manually?

Here is one version of the code that I've tried:

Code: [Select]
<? include('http://www.mywebsite.com/top_menu.php'); ?>
Code: [Select]
<? include('http://www.mywebsite.com/bottom_menu.php'); ?>
These are the errors I'm getting:

Warning: include() [function.include]: URL file-access is disabled in the server configuration in D:\Hosting\0123456\html\test\test.php  on line 69

Warning: include(http://www.mywebsite.com/top_menu.php) [function.include]: failed to open stream: no suitable wrapper could be found in D:\Hosting\0123456\html\test\test.php on line 69

Warning: include() [function.include]: Failed opening 'http://www.mywebsite.com/top_menu.php' for inclusion (include_path='.;C:\php5\pear') in D:\Hosting\0123456\html\test\test.php on line 69

Thanks!

Offline alexjb

  • Irregular
  • Posts: 20
    • View Profile
Re: PHP5 file-access is disabled...work around?
« Reply #1 on: February 09, 2010, 09:45:38 PM »
In php.ini, allow_url_fopen must be turned off. If you are able, turn it on, or contact your host.

Alternatively, there are ways around this. If both scripts are on the same server, you could do something like:

<?php
$file 
file_get_contents('bottom_menu.php'); 
eval(
$file);
?>


Depending on how you've configured your script.

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,588
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: PHP5 file-access is disabled...work around?
« Reply #2 on: February 09, 2010, 09:54:27 PM »
When you use a URL in an include statement, it causes php to make a HTTP request back to your web server, the same as if you browsed to the file. This takes 10-100 times longer than if you use a file system path. Include is intended to be used with file paths.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline jamichelliTopic starter

  • Irregular
  • Posts: 25
    • View Profile
Re: PHP5 file-access is disabled...work around?
« Reply #3 on: February 09, 2010, 10:10:04 PM »
After a bit more research, here is what I came up with...do you see any problems with this PFMaBiSmAd?

<?php 
$root 
$_SERVER['DOCUMENT_ROOT'];
include(
$root."/top_menu.php");
?>


<?php 
$root 
$_SERVER['DOCUMENT_ROOT'];
include(
$root."/bottom_menu.php"); 
?>