set values once

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • julian_m

    set values once

    let say that i want to allow someone (the site admin maybe) to chose
    certain configuration values, for instance

    * number of products per page
    * picture widht
    * back color
    ....
    ....

    Right now, i just have all those info in a php page, so it can't be
    modified
    $number of products_per_pa ge = 20;
    $picture_widht = 2;
    $back_color = #FFFFFF;

    I could keep this info in the database, but i should read it every time
    a page is rendered... (open connection, query, close conn)

    What would be the best way to do what i'm need? Is there any chance to
    "read once, keep value for ever" ?

    regards - jm

  • pizzy

    #2
    Re: set values once

    //jm,

    //I would use sessions or cookies... or you could turn on globals but i
    wouldn't recommend this...

    //example:

    //////////////////////
    //(index.php)
    ///////////////////////
    session_start() ;
    $back_color = #FFFFFF;
    $_SESSION['back_color'] = $back_color;

    //////////////////////
    //(nextPage.php)
    ///////////////////////
    session_start() ;
    <body bgcolor='<? echo $_SESSION['back_color']; ?>'>


    // I hope this helps
    // from,
    //
    // pizzy

    Comment

    • julian_m

      #3
      Re: set values once

      But this is mainly what i'm doing right now. Note that #FFFFFF is
      "static" and can't be changed without have access to .php file...

      I should try to see how products like os_commerce or the like solve
      this kind of things...

      Comment

      • pizzy

        #4
        Re: set values once

        right... you want to story users info so that when they log back in
        their settings are kept... use a database for this and query as soon as
        they login. then use my examples to display his or her values.

        Comment

        • Colin McKinnon

          #5
          Re: set values once

          julian_m wrote:
          [color=blue]
          > let say that i want to allow someone (the site admin maybe) to chose
          > certain configuration values, for instance[/color]
          <snip>[color=blue]
          >
          > I could keep this info in the database, but i should read it every time
          > a page is rendered... (open connection, query, close conn)
          >[/color]

          So put it in a file then (although it's not *that* much of an overhead using
          the DB):

          file_put_conten ts($config_file , serialize($opti ons));

          and

          $options=unseri alize(file_get_ contents($confi g_file));

          C.

          Comment

          Working...