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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.