Results 1 to 4 of 4

Thread: Login - Loading settings efficiently $_SESSION

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Login - Loading settings efficiently $_SESSION

    Does anyone have advice on building an efficient & low-server-load login when having 25 or so different boolean settings to be loaded for each page?
    expecting 200 users logged in at a time switching pages, every page has to check true/false depending on their personal settings they assign.

    eg:
    PHP Code:
    if(isset($setting1)){ makeBox(); }
    if(isset(
    $setting2)){ makeBox(); }
    if(isset(
    $setting3)){ makeBox(); }
    if(isset(
    $setting4)){ makeBox(); }
    if(isset(
    $setting5)){ makeBox(); }
    if(isset(
    $setting6)){ makeBox(); } 
    My goal is to structure it as efficiently as possible for responsiveness. My first instinct of course it to input all the settings into an array and store in a session... But is there a better option than that?

    Thanks in advance for the advice and assistance,

    -Cory

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Personally, I think you should serialize all of your boolean values and store it as one cookie.

    For example:
    PHP Code:
    <?php

    $arr 
    = array("setting1" => true"setting2" => false"setting3" => true);

    $_COOKIE["settings"] = serialize($arr);

    ?>
    Then to retrieve the settings, do something like:
    PHP Code:
    <?php

    $arr 
    unserialize($_COOKIE["settings"]);

    if(
    $arr["setting1"] === true) {  makeBox();  }

    ?>
    - Josh

  3. The Following User Says Thank You to JShor For This Useful Post:

    crobinson42 (09-19-2011)

  4. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    Do you think that would load faster then $_SESSION['settings']['setting1']
    ??

  5. #4
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Probably, since you're sending a smaller HTTP header.
    - Josh

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •