Home > Backend Development > PHP Tutorial > yii2 and php (de)serialization pitfalls

yii2 and php (de)serialization pitfalls

WBOY
Release: 2016-07-29 08:52:03
Original
1317 people have browsed it

Notes on recording roles in yii2

Today I wrote an RBAC application for yii2. I planned to simply modify the original records about roles to switch to new permissions, but then an error occurred:

  • unserialize(): Error at offset 36 of 127 bytes

After eliminating the problem of permission structure (permission name, role name, authManager type used), I think the problem is caused by changing the data of the recorded role. The original recorded permission data is as follows:


  • O:30:"consolerbacProfileAccessRule":3:{s:4:"name";s:14:"viewOwnProfile";s:9:"createdAt";i:1460293714; s:9:”updatedAt”;i:1460293714;}

Since it is a serialized array of PHP, then in the original array, regardless of the subscript or value, it will appear in the form of a value (string) after serialization. Their subscripts are all their own lengths (so it is also explained that O:30 refers to the words consolebacProfileAccessRule, which have 30 letters in total, and those represented by numbers do not need to indicate their length, such as i:1460293714;). The solution is very simple, mainly the serialization format problem. The modified permission record is as follows:


  • O:28:"consolerbacAdminAccessRule":3:{s:4:"name";s:10:"visitAdmin";s:9:"createdAt";i:1460293714; s:9:”updatedAt”;i:1460293714;}

When it comes to writing code, it means to figure out what is in it, and then work it out from the work steps one by one~ I hope these trivial problems will not bother you After all, we have been thinking about it for so long. If we don't make mistakes, we may have written more innovative code.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the pitfalls of yii2 and php (de)serialization, including the content of yii and php. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template