Created
October 15, 2012 19:47
-
-
Save scragg0x/3894835 to your computer and use it in GitHub Desktop.
Unserialize PHP Session in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unserialize_session(val): | |
if not val: | |
return | |
session = {} | |
groups = re.split("([a-zA-Z0-9_]+)\|", val) | |
if len(groups) > 2: | |
groups = groups[1:] | |
groups = map(None, *([iter(groups)] * 2)) | |
for i in range(len(groups)): | |
session[groups[i][0]] = phpserialize.loads(groups[i][1]) | |
return session |
Why not just use zip
?
groups = zip(*([iter(groups)] * 2))
for key, php_value in groups:
session[key] = phpserialize.loads(php_value)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works using python3: