Why can't the array in the SESSION be obtained sometimes?

Source: Internet
Author: User
Why can't the array in the SESSION be obtained sometimes? After logon: put the user object user into the SESSIOn & nbsp; in this way, Access & nbsp; $ _ SESSION [user] [priv]. Sometimes this is empty, and you need to access $ user $ _ SESSION [user]; & nbsp;. sometimes you can access $ _ SESSION [user] [priv] directly, why can't the array in the SESSION be obtained sometimes?
After logon: put the user object into the SESSIOn to access $ _ SESSION ['user'] ['priv']. Sometimes this is empty.
$ User = $ _ SESSION ['user']; and then access it. sometimes you can directly access $ _ SESSION ['user'] ['priv, what's going on?
My php version 5.4.22
------ Solution --------------------

This post was last edited by xuzuning at 16:34:52

You 'd better give the test code

At least the result of var_dump ($ _ SESSION ['user ']);
------ Solution --------------------
Eliminate one external cause first. Will it happen when you test and output $ _ SESSION ['user'] ['priv'], that is, when the first access has not come yet and set the session?
Cannot reproduce test solution
------ Solution --------------------
Have you ever wondered whether your code is wrong!
$ _ SESSION ['user'] ['priv'] = ''; // The value of priv is null. it is null for anyone to obtain it!

------ Solution --------------------
$ _ Default SESSION lifecycle: 20 minutes

The time has obviously exceeded.
------ Solution --------------------
Sometimes, sometimes, it may not work. you should upload a log to record the situation of each log. This facilitates debugging.
------ Solution --------------------
The first var_dump ($ _ SESSION ['user']); is there a value? We recommend that you paste the code for analysis.
------ Solution --------------------
It cannot be re-discovered. your primary generation is different from the operational generation. how can you analyze your primary generation?

When you add log, all logs are output when no record is obtained.
Var_dump ($ _ SESSION ['user']);
Var_dump ($ _ SESSION ['user'] ['priv']);
Easy to find questions.
------ Solution --------------------
No matter which method is used for the second visit, it is okay. However, for the first visit, direct reading of two-dimensional data is inevitable, but separate reading is normal, I don't know what I understand, right...

------ Solution --------------------
Is it caused by garbled characters?
------ Solution --------------------
Print_r ($ _ SESSION ['user']);
In this way, the data structure information can be obtained to make a judgment basis.
Because you cannot reproduce the error, you can only find the cause in the code that assigns a value to $ _ SESSION.

Most likely User objects retrieved from the databaseSometimes an array or an object
------ Solution --------------------
Reference:
Print_r ($ _ SESSION ['user']);
In this way, the data structure information can be obtained to make a judgment basis.
Because you cannot reproduce the error, you can only find the cause in the code that assigns a value to $ _ SESSION.

Most likely User objects retrieved from the databaseSometimes an array or an object


In fact, I think it is a problem when assigning values to sessions!
------ Solution --------------------
This is the code used by the session function to read sessions in thinkphp:

if (strpos($name, '.')) {
list($name1, $name2) = explode('.', $name);
return isset($_SESSION[$prefix][$name1][$name2]) ? $_SESSION[$prefix][$name1][$name2] : null;
} else {
return isset($_SESSION[$prefix][$name]) ? $_SESSION[$prefix][$name] : null;
}


If the session has a BUG, I think the TP user has long responded. he reads two-dimensional data directly when reading any session.
I suggest that you first look for the reason in the business logic and session assignment.
In addition, you said you had the same problem with you. I don't know if it is convenient to send some links.
------ Solution --------------------
Check whether the data retrieved from the database is abnormal.
------ Solution --------------------
Leave the Post name and wait for the php bug report ~~


------ Solution --------------------
It seems that the problem is not clear, and no reason is found.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.