PHP problem. Probably a quick fix?

software development


I’m getting the following error when trying a php include: “Warning: main(): URL file-access is disabled in the server configuration…”

Help! How do I fix this?


Jalpuna! - personal blog
this is the box - radio blog
robsdemo - self explanatory :slight_smile:


Don’t include files from a remote site? Or use Curl if you absolutely have to.

The error comes about when you try to include any file that starts with http:// or ftp://


The problem almost certainly stems from the use of a complete URL on your includes. The DreamHost wiki now has lots of information about this issue, and how to get around it:

Simon Jessey
Keystone Websites | si-blog


Wow - this is getting complex fast.

I have no idea what cURL is, but I’m working on figuring it out.

And of course, the wiki keeps going down, so I’m getting nowhere.

I’m just trying to do a php include with a link from my own site as part of a software install as the instructions require

The instructions give me this:

<?php include 'http://'. $_SERVER['HTTP_HOST'] .'/machine/index.php?clean=true'; ?>

But no matter how I try it, no luck.

Jalpuna! - personal blog
this is the box - radio blog
robsdemo - self explanatory :slight_smile:


If you are including files on your own site, you only ever need to reference it by relative file locations. Using a domain/host address it always risky.
I define a variable called ROOT_DIR in my scripts. Then use
or something similar. If I want to move the file I can and just change the location to the root_dir. Some people like to use
include($_SERVER[‘DOCUMENT_ROOT’] . “/inc/config.php”); (I think that’s right, never used it)
instead. If you are including files not stored on your server, then learning the curl library is your only chance now.


The problem lies with the use of the “http://” part of the URL. That turns your request into a remote access. The equivalent function that should work would be this:<?php include($_SERVER['DOCUMENT_ROOT']."/machine/index.php?clean=true"); ?>That assumes that the “machine” directory is within your main domain directory.

Simon Jessey
Keystone Websites | si-blog


However, the ?clean=true won’t get passed to the script correctly as it’s a direct file include, not a HTTP/1.1 GET include.

Although, you can very well set $clean = true; just before including the file.

If you must use a query string, then your best bet is to use cURL or compile your own version of PHP.


That’s interesting to know. I’ve never had an occasion to pass a variable to an included file (I could never see the point), so I didn’t know it wouldn’t work as I described.

I’d have thought it would be better to learn cURL than to compile your own version of PHP. If the site were to end up being moved elsewhere, the new host may also have allow_url_fopen disabled.

Simon Jessey
Keystone Websites | si-blog


I’ve made changes to the wiki entry on allow_url_fopen to reflect this discussion on passing variables.

Simon Jessey
Keystone Websites | si-blog


With fopen() being one of only several ways of fetching URI/URLs, I suppose it’s not particularly a deal to have URL file-access disabled, but it surely is the simplest to use fopen(). I found this to be disabled while writing a PHP content-viewer, where fopen() was my first choice for ease of use. I’ve gone with cURL, but perhaps instantiating a HTTP_Request with pear may do the trick ? fsockopen()?


Using cURL is a good way, you can keep it at that. Using sockets gets too far down into the low level network stuff that’s really not needed.


OK - looks like cURL is the answer… or, should I say, I found a way to make it work.

Now my question is how to use a relative url with cURL? Can I?

Jalpuna! - personal blog
this is the box - radio blog
robsdemo - self explanatory :slight_smile:


You can just use an include with relative URLs, but you can by adding on $_SERVER[‘HTTP_HOST’] to the front of your URL for cURL.


I did end up using cURL and just wanted to stress how completely simple it actually was, even for the naive like
myself. :^)