Php get/iterate the values of a particular session-ThrowExceptions

Exception or error:

Hy Guys
I don’t understand how take only value of first session “articoli”.
I have created three session with a differt name id.

session_id("articoli");
session_start();
... some code
session_write_close();

session_id("nome");
session_start();
... some code
session_write_close();

session_id("cognome");
session_start();
... some code
session_write_close();

the result of single session is this :
enter image description here

In “another page” how can I iterate / get the elements of the first session only?
Last question, how to kill all session?
because if I write session_destory(), kill only last session not all.

Thx a lot.

How to solve:

There’s no need for 3 sessions, use one session.

Your code can be something like:

session_start();
$_SESSION['nome'] = 'nome';
$_SESSION['cognome'] = 'cognome';
// for this case the cart is empty:
$_SESSION['cart'] = [];

// add a product:
$article = 'A-1';
$_SESSION['cart'][$article] = [
    'article' => $article,
    'price' => 100,
    'quantity' => 1,
];

print_r($_SESSION);

// add second product:
$article = 'A-2';
$_SESSION['cart'][$article] = [
    'article' => $article,
    'price' => 100,
    'quantity' => 1,
];

print_r($_SESSION);

// update quantity under article A-1:
$article = 'A-1';
$_SESSION['cart'][$article]['quantity'] += 1;

print_r($_SESSION);

Leave a Reply

Your email address will not be published. Required fields are marked *