Skip to content

Instantly share code, notes, and snippets.

@jadell
Last active June 21, 2018 01:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadell/5495413 to your computer and use it in GitHub Desktop.
Save jadell/5495413 to your computer and use it in GitHub Desktop.
Serialize PHP data like a PHP session
<?php
function session_serialize(array $data) {
$temp = $_SESSION;
$_SESSION = $data;
$out = session_encode();
$_SESSION = $temp;
return $out;
}
function session_unserialize($data) {
$temp = $_SESSION;
session_decode($data);
$out = $_SESSION;
$_SESSION = $temp;
return $out;
}
@aftabnaveed
Copy link

This requires you start php session using session_start. How do you serialize/unserialize without starting a session? I need to make it work with a Laravel application here which does not use native php sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment