#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,405
    Rep Power
    594
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    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
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You shouldn't need to include files using HTTP, instead you should use the local filesystem path to the included file.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    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
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    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.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,405
    Rep Power
    594
    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+.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  14. #8
  15. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    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.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo