W
W
wanderbit2016-07-21 13:31:26
PHP
wanderbit, 2016-07-21 13:31:26

How to get value from session array?

How to get value from session array?

$this->session->data['session_name'] = '123';

print_r($_SESSION)
( [default] => Array ( [language] => ru [currency] => USD [customer_id] => 4 [shipping_address] => [user_id] => 1 [token] => Y8mXfPEvDDHwYCuGgPYllp2Fb1PJ1lVV [name] => fio [session_name] => 123 ) )

при попытке вывода echo $_SESSION['session_name'];
 Notice: Undefined index: name in /home/u932152297/public_html/catalog/view/theme/default/template/common/header.tpl on line 106

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Express777, 2016-07-21
@wanderbit

What is [default]?
Try
$_SESSION['default']['session_name']

D
Dmitry Entelis, 2016-07-21
@DmitriyEntelis

How about a little thought?
Look at the contents of $_SESSION?
Look at the code you are calling?
Read error?

T
ThunderCat, 2016-07-21
@ThunderCat

Attention to detail distinguishes a good programmer from a calocoder. This applies to everything, including debugging, system messages, as well as normal variable naming.
once again, carefully and letter by letter, read the debug:
[default] => Array ( [session_name] => 123 )
look at what they first wrote in general $key = $_SESSION['name'] (obviously a fakap by inattention), and then pull $_SESSION ['session_name'], although the debug seems to hint that everything is put into the default $_SESSION['default'] array, not to be confused with manual addition if that happens.

W
wanderbit, 2016-07-21
@wanderbit

print_r($_SESSION) ;
if( isset( $_SESSION['name'] ) ) {
$key = $_SESSION['name'];
echo $key;
}
why if the $_SESSION array contains the name value, it is not displayed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question