# I have a module to parse serialized php sessions

**URL:** <https://www.ruby-forum.com/t/i-have-a-module-to-parse-serialized-php-sessions/183437>\
**Category:** NGINX\
**Created:** [February 14, 2010, 3:14am UTC](https://www.ruby-forum.com/t/i-have-a-module-to-parse-serialized-php-sessions/183437 "2010-02-14T03:14:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauro\_Stettler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@Mauro\_Stettler](https://www.ruby-forum.com/u/Mauro_Stettler)\
**Post date:** [February 14, 2010, 3:14am UTC](https://www.ruby-forum.com/t/i-have-a-module-to-parse-serialized-php-sessions/183437/1 "2010-02-14T03:14:12Z")

</div>

hi

i recently wrote an nginx module that can extract certain values out  
of a serialized php session. in my case i’m retrieving the php session  
from a memcache. this thing isn’t tested in prod, in fact i started it  
yesterday. but it seems to work and i can’t find any bigger problems  
with it at the moment.

currently it works like this:

33 location / {  
34 eval $session {  
35 set $memcached\_key  
“d41d8cd98f00b204e9800998ecf8427e:5b9hm9rspbgajg22eqpqs6ang1”;  
37 memcached\_pass 192.168.1.237:11210;  
38 }  
…  
44 php\_session\_parse $admin\_right $session  
“symfony/user/sfUser/attributes|s:10:"subscriber";s:7:"isAdmin"”;  
…  
53 if ($admin\_right = “b:1”)  
54 {  
55 # do something  
56 }

i think the format how i am specifying the value that i want to  
extract from the session might be a little confusing (and there are no  
docs yet). in the example the value that i want to extract is  
specified with the string:

"symfony/user/sfUser/attributes|s:10:"subscriber";s:7:"isAdmin"

which means on the toplevel array i want the element  
“symfony/user/sfUser/attributes”, second level i want the element  
“s:10:"subscriber"”, third level i want the element  
“s:7:"isAdmin"”. separators between the elements are ; and |. this  
might seem confusing, but thats the way how its done in the php  
session serialization…

i would be happy about some feedbacks. could a thing like this be  
useful? i’m sure there are still bugs too…

thats the link:

> **[GitHub - replay/ngx\_http\_php\_session: nginx module to parse php sessions](https://github.com/replay/ngx_http_php_session)**
>
> nginx module to parse php sessions. Contribute to replay/ngx\_http\_php\_session development by creating an account on GitHub.

mauro
