I am including a file called includes/db.php which in turn requires connection_details.php
The issue I am having is I must read the content of db.php with this following line.
$dbSettingsFile = realpath( dirname( __FILE__ ) )."\connection-details.txt";
$lines = file($dbSettingsFile);//file in to an array
But if I am in turn already including the db.php file from a file that is something like. /subfolder/file.php
with the line
require('../includes/db.php');
But this will always work on windows but am I right in saying because of the backward slash in the $dbSettingsFile variable it will not work in linux? I have to be very specific like this because if you removed the realpath and ran file.php it would not pick up the correct path.
You should always use absolute filename, because you can't be sure about base directory where search for relative path will start.
Use
require( __DIR__ . '/../includes/db.php' );
to be sure.
Slash character '/' will work as directory separator in both Windows and Linux. Be careful - in Windows filenames 'db.php' and 'DB.php' are the same file but not in Linux.