How do I remember the user name when logging on to yii?

Source: Internet
Author: User
When using yii to log on, I set the second parameter $ duration to 86400, which saves the user's login information to the cookie for 24 hours. {Code...} when I want to parse the cookie, I find that the cookie is like this. {Code ...} but how can I parse this... when using yii to log on, I set the second parameter $ duration to 86400, which saves the user's login information to the cookie for 24 hours.

Yii::app()->user->login($identity,86400);

When I want to parse the cookie, I find that the cookie is like this.

array(4) {  ["CNZZDATA2724999"]=>  string(48) "cnzz_eid=1338694115-1438177009-&ntime=1438182411"  ["Hm_lvt_598eaf80391e655d10ebe38419b36fb2"]=>  string(32) "1438310921,1438410705,1438589813"  ["PHPSESSID"]=>  string(26) "8ak62atemv5t4vc67hjrj1l705"  ["abed3dd2114943c0bf392b4ae87e177b"]=>  string(139) "d6991a57d52238c7b0b10d36c07f1fd9b715532ea:4:{i:0;s:2:"27";i:1;s:5:"endui";i:2;i:86400;i:3;a:2:{s:4:"role";s:1:"1";s:4:"name";s:5:"endui";}}"}

But how can I parse this cookie? What method is used?

Reply content:

When using yii to log on, I set the second parameter $ duration to 86400, which saves the user's login information to the cookie for 24 hours.

Yii::app()->user->login($identity,86400);

When I want to parse the cookie, I find that the cookie is like this.

array(4) {  ["CNZZDATA2724999"]=>  string(48) "cnzz_eid=1338694115-1438177009-&ntime=1438182411"  ["Hm_lvt_598eaf80391e655d10ebe38419b36fb2"]=>  string(32) "1438310921,1438410705,1438589813"  ["PHPSESSID"]=>  string(26) "8ak62atemv5t4vc67hjrj1l705"  ["abed3dd2114943c0bf392b4ae87e177b"]=>  string(139) "d6991a57d52238c7b0b10d36c07f1fd9b715532ea:4:{i:0;s:2:"27";i:1;s:5:"endui";i:2;i:86400;i:3;a:2:{s:4:"role";s:1:"1";s:4:"name";s:5:"endui";}}"}

But how can I parse this cookie? What method is used?

// Cookies $ cookie = array ('cnzzdata2724999 '=> 'cnzz _ eid = 1338694115-1438177009-& ntime = 000000', 'hm _ 0000' => '2017 8410705, 1434789813 ', 'phpsessid' => '8ak62atemv5t4vc67hj1_1l705 ', 'clerk' => 'salary: 4: {I: 0; s: 2: "27"; I: 1; s: 5: "endui"; I: 2; I: 86400; I: 3; a: 2: {s: 4: "role"; s: 1: "1"; s: 4: "name"; s: 5: "endui" ;}} '); // regular $ regExp ='/(a: \ d + :{. +) $ /';
/* Specify the key to store the cookie value */$ cookieUserInfo = end ($ cookie); $ getUserInfoStr = preg_match ($ regExp, $ cookieUserInfo, $ matchedStr ); $ getUserInfo = $ matchedStr [1]? Unserialize ($ matchedStr [1]): array (); print_r ($ getUserInfo );
/* If a random key is stored at a certain location */$ getUserInfo = array (); foreach ($ cookie as $ cookieUserInfo) {if (preg_match ($ regExp, $ cookieUserInfo, $ matchedStr) {$ getUserInfo = unserialize ($ matchedStr [1]); break ;}} print_r ($ getUserInfo );

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.