Jump to content

[SOLVED] Simple document root/public html question


Prodigal Son

Recommended Posts

Ok, bit of a newb question, but I always hear of people saying to place files above the public html or document root folder for sensitive files. So do I just do this:

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

 

Or is there something else your supposed to do? Some say to never use ../ when including files so not sure.

 

Thanks.

if your file structure is like:

/
  php/
    something/
      file.php
    include_file.php
    config.php
  web/
    index.php
    page.php

 

then on index.php and page.php, just use:

include('../php/config.php');

and on something/file.php use:

include('../../php/config.php');

 

BUT, if in config.php, you want to include include_file.php, you need to do something different. Since the Current Working Directory might web/ or it might be web/something/, a simple relative path won't work. So, to get the path relative to config.php use:

include(dirname(__FILE__).'/include_file.php');

 

make sense?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.