Log in

View Full Version : Login - Loading settings efficiently $_SESSION



crobinson42
09-19-2011, 08:28 PM
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:


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

JShor
09-19-2011, 08:46 PM
Personally, I think you should serialize all of your boolean values and store it as one cookie.

For example:


<?php

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

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

?>


Then to retrieve the settings, do something like:


<?php

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

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

?>

crobinson42
09-19-2011, 08:55 PM
Do you think that would load faster then $_SESSION['settings']['setting1']
??

JShor
09-20-2011, 06:20 AM
Probably, since you're sending a smaller HTTP header.