Jump to content

PHP5 file-access is disabled...work around?


jamichelli

Recommended Posts

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:

 

<? include('http://www.mywebsite.com/top_menu.php'); ?>

 

<? 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!

Link to comment
https://forums.phpfreaks.com/topic/191568-php5-file-access-is-disabledwork-around/
Share on other sites

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.

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.

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"); 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.