using a variable

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
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

using a variable

Post by johnhelen »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello all

I declare a variable in a file "config.inc" in a folder called "inc"  as:

Code: Select all

<?php

$DATABASE_NAME = "database";

?>

Then in my main script called myscript.php, I have

Code: Select all

<?php

required_one ("inc/config.inc");

if ($DATABASE_NAME =="database") {

  }

?>

This way is working but I do not know that is good or not

Please help

many thanks
john


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

If it is a value that never changes throughout the lifetime of your script, such as a database name or password or something, then use a constant. Check out the documentation for define().
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Avoid using constants for (database) credentials. Since they cannot be destroyed, any malicious code introduced through a vulnerability would allow the attacker to gain access to its contents.
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

Thanks all and feyd

Post by johnhelen »

regards
Post Reply