Jump to content

$_SERVER['DOCUMENT_ROOT'] wont go back levels


xc0n

Recommended Posts

Ok so i want to stop my config file from being accessed directly through a browser, the best way to do this is to not have config.php

in my public_html folder, that way i can include it in a file but its not accessible directly. eg below:

 

/home/esecure/public_html/index.php

/home/esecure/hidden_files/config.php

 

now index.php requires config.php to run so ive used the codes:

 

<?php require($_SERVER['DOCUMENT_ROOT'] . '/../hidden_files/config.php'); ?>

 

But it wont work. It wont go back past public_html folder i just get an error.

 

Warning: require(/home/esecure/public_html/../config.php) [function.require]: failed to open stream: No such file or directory in /home/esecure/public_html/config.php on line 13

 

The code below works, but i dont want to link to config this way i want the above way to work. What am i missing?

 

<?php require '/home/esecure/hidden_files/config.php' ?>

 

thanks in advance

 

 

index.php runs

 

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

 

but index.php in in the public_html folder so the code you gave me aboce will be looking in /home/user/public_html/hidden_files instead of /home/user/hidden_files

 

any other ideas?

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.