john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

php include continued url file access is disabled

URL File-Access is Disabled in the Server Configuration

If you've coded an "include file" into your php (perhaps php version 4?)...

<?php
    include ("http://website.com/includes/header.php");
?>

/*Warning: include() [function.include]: URL file-access is disabled in the server configuration
 in /home/YourUsername/public_html/index.php on line xx */

This is because in PHP 5 (or perhaps as part of a server security upgrade)
the allow_url_fopen is set to OFF... meaning absolute paths to other sites on the
internet aren't allowed.

The alternatives are:

RELATIVE PATHS

<?php
    include (header.php);       //include a file in the same directory
    include (includes/header.php);      //include a file from a directory under the PHP file
    include (../header.php);        //include a file from a directory above the current PHP file
?>

USING A TRUE "ABSOLUTE URL" FUNCTION

<?php
    $File = file_get_contents("http://website.com/includes/header.php");
    echo $File;
?>

SERVER VARIABLES

?php
    include $_SERVER['DOCUMENT_ROOT'] . '/includes/header.php';
?>



//also note that some hosts have enabled "Options +Indexes"
(where a directory without an index.htm file is displayed as a list of files)

You SHOULD disable that listing using a .htaccess file (at the highest directory possible)
Options -Indexes

BECAUSE if you want to share things, then create a file to list them... but sharing
everything by default is a BIG security and privacy concern...

  • « Linux install trac on centos5 or debian
  • drupal backing up and restoring »

Published

Feb 10, 2010

Category

php

~198 words

Tags

  • access 8
  • continued 26
  • disabled 2
  • file 92
  • include 6
  • is 5
  • php 82
  • url 14