#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    PHP TO CREATE A CONFIG or properties file


    Hi All,
    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

    Regards,
    Sandeep
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,871
    Rep Power
    6351
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    Does this have to be a physical file? Have you worked with MySQL before? Perhaps a database may also be an option for you?
  6. #4
  7. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    Does this have to be a physical file? Have you worked with MySQL before? Perhaps a database may also be an option for you?
    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:

    PHP Code:
    //

    //build from user supplied input - remember to sanitise first!!!!!

    $config = array(
         'username'=>'username',
         'password'=>'password',
         'host'=>'localhost',
         'dbname'=>'mydatabase'
    );

    //build string using var_export

    $c = '<?php $config '.var_export($config,1).";";

    //write to file

    file_put_contents("config.inc.php",$c);
    which would write

    Code:
    <?php $config = array(
         'username'=>'username',
         'password'=>'password',
         'host'=>'localhost',
         'dbname'=>'mydatabase'
    );
    to the file "config.inc.php"

    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.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  8. #5
  9. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,998
    Rep Power
    9397
    Also consider alternative file formats like JSON or XML. Both are very easy to read and write.
  10. #6
  11. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    Originally Posted by requinix
    Also consider alternative file formats like JSON or XML. Both are very easy to read and write.
    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).

    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.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo