intregrisist Posted April 13, 2008 Share Posted April 13, 2008 Hi, this may be verry easy to fix but I just can't find a solution. I've been reading and following a book on PHP and Mysql and I just can't get my php file to run my other php file with the require() function. This is my code: <?php require($_SERVER['DOCUMENT_ROOT'] . "/config/config.php"); $connection = mysql_connect($db_host, $db_user, $db_password) or die("error on connect"); echo "connection made"; ?> Thats all it is... My config.php file is one folder up called config. ex. document_root/config/config.php document_root/index.php <---very simple yet can't find it ??? I get the following: Warning: require(/home/content/.../html/config/config.php) [function.require]: failed to open stream: No such file or directory in /home/content/..../html/temp_folder/index.php on line 2 Fatal error: require() [function.require]: Failed opening required '/home/content/.../html/config/config.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/.../html/temp_folder/index.php on line 2 Please help... Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/ Share on other sites More sharing options...
raku Posted April 13, 2008 Share Posted April 13, 2008 Try getting rid of the $_SERVER['DOCUMENT_ROOT'] Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/#findComment-515850 Share on other sites More sharing options...
intregrisist Posted April 13, 2008 Author Share Posted April 13, 2008 Dindn't work...I get the same error. Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/#findComment-516223 Share on other sites More sharing options...
BlueSkyIS Posted April 13, 2008 Share Posted April 13, 2008 index.php is in $_SERVER['DOCUMENT_ROOT']."temp_folder/index.php", not $_SERVER['DOCUMENT_ROOT']."/index.php". is /config/config.php in temp_folder also? Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/#findComment-516232 Share on other sites More sharing options...
discomatt Posted April 13, 2008 Share Posted April 13, 2008 Also, unrelated to your problem... but i find it best practice to store sensitive information outside the webroot, and include it from there... ie: require($_SERVER['DOCUMENT_ROOT'] . "/../config/config.php"); Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/#findComment-516240 Share on other sites More sharing options...
intregrisist Posted April 13, 2008 Author Share Posted April 13, 2008 yes: /config/config.php I have my <temp_folder> inside I have index.php and another folder called <config> inside that folder there is my config.php file which I am trying to reference inside of my index.php Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/#findComment-516257 Share on other sites More sharing options...
intregrisist Posted April 13, 2008 Author Share Posted April 13, 2008 I GOT IT WORKING YEY Thanks to BlueSkyIS!! It was killing me to not get this connection going. I am so happy thank you. For anyone who has the same problem here is the code: require($_SERVER["DOCUMENT_ROOT"] . "/temp_folder/config/config.php"); $connection = @mysql_connect($db_host, $db_user, $db_password) or die("error on connect"); echo "connection made"; The error was that $_SERVER["DOCUMENT_ROOT"] was one folder behind in my way of thinking about it. I had to include the folder my index.php file was on: "/temp_folder/config/config.php" The book explained it differently. Link to comment https://forums.phpfreaks.com/topic/100871-require-failed-to-open/#findComment-516263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.