LeonLatex Posted July 8, 2023 Share Posted July 8, 2023 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 8, 2023 Share Posted July 8, 2023 Print out the value of the DOCUMENT_ROOT and see what happens when you try to add "../includes/db.php" to it. Quote Link to comment Share on other sites More sharing options...
Solution Strider64 Posted July 9, 2023 Solution Share Posted July 9, 2023 if you 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 Quote Link to comment Share on other sites More sharing options...
LeonLatex Posted July 9, 2023 Author Share Posted July 9, 2023 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.