Page 1 of 1

PHP design question

Posted: Wed Jan 28, 2004 8:14 am
by pinehead18
What i'm needing to do is write a config file which i keep in the main www dir.
In this file i'm able to set the mysql db username and pass as long with the site name.

First off. My question is how would i set that inside of the config file?

$sitename = "whatever";
Global $sitename; ?

Once i have it set.. How would be the best way to call those vars from the config file. I.E

include('config.inc');

$_GET['sitename']; ??

Thank you for your time and help and most of all patients.

- Anthony

config file with db access

Posted: Wed Jan 28, 2004 8:37 am
by jmhowitt
I usually put in an seperate file and then include it in the files i wish to use it in. then you don't need to make it global

$hostname = "localhost" ;
$user = "username" ;
$password = "1234567890" ;
$database = "help_me" ;
$cn=mysql_connect($hostname,$user,$password);
mysql_select_db($database);

include("include_files/dbacc.php");

Posted: Wed Jan 28, 2004 9:36 am
by McGruff
Make sure it's in a safe folder ie outside the web root (if you can) or at least .htaccess / deny from all the parent directory.

If you include a file, any variables defined in the included file are immediately available in the same scope as the line where the include call was made.