FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


saving variables





golles
what is the best way to save text, like number of rows for the questbook and the admin name.
should I save it to a php file like:

Code:
<?php
$qbrows = "10";
$admin_name = "golles";
?>

or should I save it to a database? but isn't it really stupid to save 1 variable to a db?

maybe there or other suggestions?
rohan2kool
you can do it either way you want. If needed, you can save it to a php file and then call it using 'include()' in php and use the variables. Or, you can save it in a text file in various formats (like XML or maybe .ini-styled) and then parse it from the php. If needed, you can also use MySQL to save it (in case the info is confidential)... nothing's silly if it serves the purpose Very Happy

as a part of the recommendation, i'd recommend u storing it as a php file with the variables stored by define() rather than $varname (no specific reason.. just personal preference Very Happy ).
AftershockVibe
Storing that information in a database rather defeats the object, as you'd have to specify database credentials to get your administrator credentials, which is like keeping your front door key in a box locked with a key.

I therefore recommend doing things like most PHP programs do and just storing the information in a flat .php file. If it's good enough for PHPBB, it's good enough for this.

You can simply specify the information exactly the way you originally suggested.

However, for reasons of safety you may only want these variables to be able to be defined from within a certain file (or files).

If you add the following code snippet to the top of the file, this will only allow the variables to be defined when the visitor is looking at a certain page;

Code:

IF (eregi('index.php', $_SERVER['PHP_SELF']))
   {

      die ('This is a protected file and cannot be accessed.');
   }


In this case it will only allow definition from scripts which are called from within index.php.

Notes: This is not necessarily direct, if index.php included another file which included that one it would still accept it.
Also, files including index.php will NOT be able to access it.
Philip
i think it's not really dumb for save 1 variable in db,
just u need to know how to keep it effecient.

like making a table config_portal
Quote:
Config | Value
qbrows | 10
admin_name | gollas
ammonkc
Yeah, it would be more trouble to have to query you db everytime you needed that 1 variable. if it were a lot of variables and each user had different values for each variable (IE custom user prefferences) then a db would be the way to go.
I always save my db connection script variables in an include file called config.php and require() it whenever its needed.
Related topics
How To : Improve Your PHP Programming
Fortran Tutorials(77)
PHP Includes and Variables?
Problem with session variables
Separating contents of MySQL row and put them in variables?
Cat Interrupts Catnap, Possibly Saving Two
problem adding variables in javascript
PHP Tutorials
My forum isn't saving cookies
Scroogle
SPi Post - Man weigh 1.2K pounds seeks life-saving surgery
using variables
(Khaos) Device to saving gas, what is your opinion ?
I'm doing something wrong,,,
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.