Last active
June 21, 2018 01:29
-
-
Save jadell/5495413 to your computer and use it in GitHub Desktop.
Serialize PHP data like a PHP session
This file contains 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
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.