PHP parse_ini_file problems

Lee, if your document you are trying to access is in the folder root/cfi/config.ini this looks very much like it is outside the scope of the $_SERVER['Document_Root']; variable - which would look something like:

/home/accountname/websitefolder/

Your ini file sounds like it is located in the folder

/home/accountname/root/cfi/

Which means you will not reach it. You can debug if the address is correct with :

if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/cfi/config.ini")){
print fileperms($_SERVER['DOCUMENT_ROOT'] . "/cfi/config.ini");
}
else {
die("does not exist at this location");
}

The fileperms function will feedback the access permissions for the file which may be preventing PHP reading it, if the file is located in the correct place.

ini file Structure:

Also, You will need to confirm your ini file is the correct structure, the ini file needs to be a valid ini structure like the php.ini file, see http://php.net/manual/en/function.parse-ini-file.php

(edit: for the benefit of BoltClock's edit, I want to retain the above statement regarding the structure of the ini file as this was actually the cause of the OP problem, I have however reworded it. Thank you)

Additional:

Error tracking is vital to finding out why things went wrong: From this post on SO - How to log errors and warnings into a file? - and from the wise advice of Fred-ii- anyone can add the following to the top of their file for some error feedback:

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");

This will look excessive to those that know, but the above code in order will:

report all errors
display these errors to the browser
log these errors to the log file
set where the log file lives. 

Displaying and logging files isn't needed but I put both in so people can choose their method. Displaying errors to the browser should always be disabled with production servers.

Now, you have a log file with many errors in it, you need your (S)FTP program to look in the folder for it, the folder stated above /tmp/ is NOT in your website domain folder, but in a companion folder, next to it, so you need (S)FTP to access it. Log in, find the folder, and file and download it. Open it with a text editor and it will give you your errors. Delete the file from the server and a new one will be generated when new errors occur.

Tags:

Php