Jump to content

Create link out of a global and set a variable


LeonLatex
Go to solution Solved by Strider64,

Recommended Posts

I have put the PDO database connection one level above (outside) the WWW directory on the server to protect it from unwanted visitors who get hold of the user data of the database server.
Today I use this in other places than where it says now, but it is only as an example:
include __DIR__ . '/../includes/db.php';

but then I thought of the super global $server , but I can't get it to work. I have set it up like this:
include($_SERVER['DOCUMENT_ROOT'] . "../includes/db.php");

What am I doing wrong? Or won't it work with the super global example?

And how do I create a variable out of the super global string so I only use $linkpath in front of the path to the file I want to link to?

Link to comment
Share on other sites

14 hours ago, Strider64 said:

if your file is outside the root directory you should use

include(__DIR__ . "/../includes/db.php");

$_SERVER['DOCUMENT_ROOT'] returns the root directory defined by the server configuration file.

Thanks for the answer to both of you. I tried as Requinix said to print out the path and found out the difference between those two.

Link to comment
Share on other sites

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.