Have two open sessions?

0

I want to have two open sessions.

One to save user data and another to save shopping cart data.

It may or may not, try to rename the session but it still does not work.

EDIT: In this part of here I try to save the id of a product in the "car" session

$_SESSION['carro'][$id]

And here I keep the id and the name of the user that has been logged

$_SESSION['user']['id'] = $iD;
$_SESSION['user']['name'] = $usern;

I try to save variables in different sessions.

    
asked by Thunder 31.07.2017 в 00:59
source

2 answers

0
  

$_SESSION is a superglobal variable that stores an associative array with all session variables. If you need to save more than one value, just specify the key (it can be a string or a number) and its contents.

Documentation

The problem is that you are creating the key dynamically and it will depend on the value you get from the database. Also, the key ['carro'][$id] is only initialized but has no value.

$_SESSION['carro'][$id];

The solution is to write the key of the session variable in quotation marks and assign it the value of the variable $id .

$_SESSION['carro']['id'] = $id;

If you want to get the value of the session variable ['carro]['id'] :

echo $_SESSION['carro']['id'];
// 5
    
answered by 31.07.2017 в 01:19
-2

Sure, it simply uses names of different sessions.

For example:

$_SESSION['USUARIO']['user']...
    
answered by 31.07.2017 в 01:11