1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

writing configuration files in php?

Discussion in 'Programming & Webmastering' started by aximbigfan, Feb 3, 2008.

  1. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    848 (0.26/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    Anyone know how to write configuration files in PHP?

    I have though of a few ways, but non work really well.

    Basically, I just want to write variables and values, to be used by a PHP app for its configuration.

    For example

    have a webui where the user says that they want "white" to be a background color, and "blue" be the text color. So they click on submit, and the PHP script opens config.php, and writes the following to it...

    $bgcolor = "white";
    $textcolor = "blue";


    Chris
     
  2. y2kbugger New Member

    Joined:
    Dec 24, 2007
    Messages:
    14 (0.00/day)
    Thanks Received:
    2
    Location:
    austintown, oh
    would this be per user, or like a site admin?
     
  3. Jizzler

    Jizzler

    Joined:
    Aug 10, 2007
    Messages:
    3,628 (1.23/day)
    Thanks Received:
    721
    Location:
    Geneva, FL, USA
    If you're on php5, file_put_contents() wraps up fopen(), fwrite() and fclose() into one nice little function.

    PHP:
    // Possibly done during account creation with default values
    $userInfo = array('BgColor' => '#FFFFFF''TxtColor' => '#000000');
    file_put_contents('user.info'serialize($userInfo));

    // Pulling the values...
    $userInfo unserialize(file_get_contents('user.info'));
    Depending on how you identify users, could save them as $username.'whatever'.
     
  4. aximbigfan New Member

    Joined:
    Oct 15, 2006
    Messages:
    848 (0.26/day)
    Thanks Received:
    35
    Location:
    St. Louis, MO
    Thanks Jizzler!

    Chris
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page