PHP design question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

PHP design question

Post 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
jmhowitt
Forum Newbie
Posts: 1
Joined: Wed Jan 28, 2004 8:37 am
Location: England

config file with db access

Post 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");
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply