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

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.