The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP5 - Question on Include Files
Discuss Question on Include Files in the PHP Development forum on Dev Shed. Question on Include Files PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 16th, 2012, 03:53 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 9 m 14 sec
Reputation Power: 0
|
|
|
PHP5 - Question on Include Files
Hello. I have a PHP issue and require some assistance. I’m not sure what caused this issue - going from PHP4 to PHP5, or a PHP configuration setting that my web hosting company made. In PHP4 I was able to include a page of code in my web apps that was hosted on another URL by using the following:
require(" http:// myincludes.mysite.com / inc_myfunctions.php "). This allowed me to have all my common functions and components used by different web applications in one location and not have to have a copy of them in each web app directory. If I made a change to a function, or added a function, I only had to do it in one place and the change became available to all my web apps. Now with PHP5, I cannot include a page that resides on another URL. This means that I am going to have to have a copy of all my function pages and components in the directory of each of my web apps – And when I need to make a change, I will need to make that change in each location. Does anyone know of a workaround or have an idea of another way to implement this to meet my needs of having them located in one location? Please note that each web app has it’s own URL. Any help will be greatly appreciated.
Thanks,
Gary
|

December 16th, 2012, 04:41 PM
|
|
|
|
The setting 'allow_url_include' is off by default in PHP 5. You need to turn it on.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

December 16th, 2012, 04:45 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 9 m 14 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by gw1500se The setting 'allow_url_include' is off by default in PHP 5. You need to turn it on. |
Thanks for your reply, but unfortunately I cannot turn it on. That is controlled by the hosting company.
Gary
|

December 16th, 2012, 04:59 PM
|
 |
Lost in code
|
|
|
|
|
You shouldn't need to include files using HTTP, instead you should use the local filesystem path to the included file.
|

December 16th, 2012, 05:04 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 9 m 14 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by E-Oreo You shouldn't need to include files using HTTP, instead you should use the local filesystem path to the included file. |
Thanks for your reply. Can you elaborate and possibly provide an example?
Gary
|

December 16th, 2012, 07:07 PM
|
 |
Lost in code
|
|
|
|
For example,
PHP Code:
include('/var/www/myincludes/inc_myfunctions.php');
Except that I don't know the path to the files on your server, so you have to fill that in.
|

December 16th, 2012, 07:20 PM
|
|
|
|
I think the crux of the problem is that the OP is trying to access a single file from multiple servers to avoid duplicating that file on each. If that file is just HTML then 'fopen' is a better option but even then 'allow_url_include' must be enabled for PHP5+.
|

December 16th, 2012, 09:08 PM
|
 |
Lost in code
|
|
|
|
|
In that case I recommend duplicating the code to each server, sharing it between the servers using a network share, or using JavaScript to retrieve the shared HTML.
There is a reason allow_url_include is disabled by default in PHP: because it's inefficient, not particularly secure and rarely necessary.
The file handling functions like fopen and file_get_contents actually check against allow_url_fopen instead of allow_url_include. allow_url_fopen is enabled by default. This is still inefficient, but doesn't have the same security implications as including a remote file.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|