Jump to content

[SOLVED] session arrays


gish

Recommended Posts

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

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.

 

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 ";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.