gish Posted January 27, 2009 Share Posted January 27, 2009 When writing session variables into your script is it better for the web servers security, speed and resource to have the following, $_SESSION['login']= 0; $_SESSION['username']= $username_variable; $_SESSION['address']= $address; $_SESSION['phone']= $phone; or $_SESSION['information'] = array(); $_SESSION['information]['username'] =$username_variable; ; $_SESSION['information']['address']= $address; $_SESSION['information']['phone']= $phone; The reason I am asking is I am about to start a large personal project and it has to have quite a few session variables and I don't want to cause an issue. After looking at the plan I have in place most of them could go into a single array. But I am not sure if that is of any advantage. Gishaust Link to comment https://forums.phpfreaks.com/topic/142560-solved-session-arrays/ Share on other sites More sharing options...
ratcateme Posted January 27, 2009 Share Posted January 27, 2009 really for security neither have any real difference with speed the first is proberly faster but by such a small margin it really doesn't matter also you don't need the first line in the second example it will work just fin without it Scott. Link to comment https://forums.phpfreaks.com/topic/142560-solved-session-arrays/#findComment-747166 Share on other sites More sharing options...
redarrow Posted January 27, 2009 Share Posted January 27, 2009 There no difference, but you can use the combination off both, it will be better, to understand all the session, if there so many to use. Link to comment https://forums.phpfreaks.com/topic/142560-solved-session-arrays/#findComment-747180 Share on other sites More sharing options...
redarrow Posted January 27, 2009 Share Posted January 27, 2009 you could use the sessions to organize all you data out put i guess. <?php session_start(); // session user info. $_SESSION['user_info']['id']="0005"; $_SESSION['user_info']['name']="redarrow"; $_SESSION['user_info']['surname']="redarrow"; // let say user messages $_SESSION['user_messages']['msg1']="my name is redarrow"; $_SESSION['user_messages']['msg2']="redarror loves php"; $_SESSION['user_messages']['msg3']="redarrow loves mysql and php"; //let say user payments $_SESSION['user_payments']['pay1']="£100"; $_SESSION['user_payments']['pay2']="£600"; $_SESSION['user_payments']['pay3']="£1000"; echo "my name is {$_SESSION['user_info']['name']}\n<br> {$_SESSION['user_messages']['msg1']}\n i have currently paid you {$_SESSION['user_payments']['pay1']}\n "; ?> Link to comment https://forums.phpfreaks.com/topic/142560-solved-session-arrays/#findComment-747191 Share on other sites More sharing options...
gish Posted January 27, 2009 Author Share Posted January 27, 2009 thanks Link to comment https://forums.phpfreaks.com/topic/142560-solved-session-arrays/#findComment-747232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.