Jump to content


Photo

'parse_ini_file' Absolute Link Problem


  • Please log in to reply
2 replies to this topic

#1 paulherron

paulherron
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 July 2006 - 02:34 PM

Hi everyone. I'm trying to parse a .ini file called "site_config.ini". If I put it in the same directory as the executing script I have no problems with the following code:

$ini_filename = 'site_config.ini';
// Read .ini file if it is present.
	$ini = parse_ini_file($ini_filename, false);

However, if I expand this code to point to a different directory...

$ini_path = 'http:www.mydomain.com/includes/';
$ini_filename = 'site_config.ini';
// Read .ini file if it is present.
	$ini = parse_ini_file($ini_path.$ini_filename, false);

... I get an error: "Warning: parse_ini_file(): Cannot open 'http://www.mydomain....site_config.ini' for reading in /home/blah/blah/".

I know the file is present in that directory because I can navigate to it.

Putting both the path and the filename together in the same variable doesn't seem to work either.

Any ideas?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 02:48 PM

Do not use a URL to access a file on the same domain as your script. If the INI file is in a directory that is in the same directory as the script, just do
<?php
$ini_file = 'includes/site_config.ini';
$ini = parse_ini_file($ini_file);
?>

Ken

#3 paulherron

paulherron
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 July 2006 - 03:46 PM

That's great, thanks Ken! Am I right in saying that using external URLs is a bad idea anyway because it slows the processing down significantly?

The includes folder is actually on the same level as the directory containing the script, so I got it working with:

<?php
$ini_file = '../includes/site_config.ini';
$ini = parse_ini_file($ini_file, false);
?>

I then developed that to the following to allow the code to work no matter what directory level it's placed at:

<?php
$ini_file = $_SERVER['DOCUMENT_ROOT'].'/includes/site_config.ini';
$ini = parse_ini_file($ini_file, false);
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users