Include in absolute address

1

I am trying to include the config.php file that is in the root folder of the site. However, I also have the header.php file in the root of the site and all pages are in a folder with this name, so the file looks like this.

<?php
include('../config.php');
include('../header.php'); ?>
conteudo...
</?php include('../footer.php);
  

For absolute link already tried:

include("http://".$_SERVER['SERVER_NAME']."/config.php");

  

Error displayed on online server:

I did not succeed either.     Warning     : include (../config.php): failed to open stream: No such file or directory in     /home/u655246247/public_html/paginas/artigos.php     on line     2

  

Line 2: that's exactly where I want to go - >    include ('../ config.php'); .

    
asked by anonymous 23.01.2016 / 01:11

1 answer

4

This is probably what you are looking for:

include( $_SERVER['DOCUMENT_ROOT'] . '/config.php' );

So you have the absolute path of include in relation to the disk, not the URL of the site.

If you're curious to understand, use this line in a test script:

echo $_SERVER['DOCUMENT_ROOT'];

The result will be something like /var/www/httpdocs on Linux, or something like c:\apache\httpdocs on Windows.

Notes:

  • Make sure the file name is correct. Config.php and config.php are not the same file in Linux.

  • Also make sure the files involved are read permission to the page server.

  • Of course, the file must be in the same folder as the path indicated:)

23.01.2016 / 01:20