January 22nd, 2013, 05:01 AM
PHP TO CREATE A CONFIG or properties file
I am new to PHP , i am in need of a PHP program which can accept input through form and write that into a config or properties file as key value pair
THanks in advance
January 22nd, 2013, 07:54 AM
And what have you tried so far? We don't do free work here, this is a help board.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
January 22nd, 2013, 09:08 AM
Does this have to be a physical file? Have you worked with MySQL before? Perhaps a database may also be an option for you?
January 22nd, 2013, 10:51 AM
Such a file might store connection details to a database, and you could achieve such output using [PHPNET="var_export"]var_export()[/PHPNET]
you might do something like:
which would write
//build from user supplied input - remember to sanitise first!!!!!
$config = array(
//build string using var_export
$c = '<?php $config = '.var_export($config,1).";";
//write to file
to the file "config.inc.php"
<?php $config = array(
some other code would then include config.inc.php and $config would be available as expected
Last edited by Northie; January 22nd, 2013 at 10:57 AM.
January 22nd, 2013, 12:01 PM
Also consider alternative file formats like JSON or XML. Both are very easy to read and write.
January 22nd, 2013, 05:24 PM
But for a php application I would always recommend storing such data as raw php - it will execute an awful lot quicker as there is no overhead in decoding the data (XML or json).
Originally Posted by requinix
The caveat is always security and making sure that executable code which does something is not stored. So validate your data for type and sanitise for use.