Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Forked from scragg0x/gist:3894835
Last active August 7, 2016 12:14
Show Gist options
  • Save catwhocode/27460d55ce1c9a37a98d to your computer and use it in GitHub Desktop.
Save catwhocode/27460d55ce1c9a37a98d to your computer and use it in GitHub Desktop.
Unserialize PHP Session in Python
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment