Speed up development with full-stack environments for every branch.

Learn More

Encode / Decode session data [PHP]

1262 Runs 4767 Views 836 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php
/*
 * PHP Session - Encode / Decode session data
 */

//start the session
session_start();

$_SESSION['fistvar'] = 'a random value';
$_SESSION['secondvar'] = 24;

//session_encode() returns a serialized string of the contents of the current session data 
//stored in the $_SESSION superglobal
$enc = session_encode();
echo "The serialized string of the current session : ".$enc.'<br />';

unset($_SESSION['fistvar']);
unset($_SESSION['secondvar']);

//session_decode() decodes the serialized session data provided in $data, 
//and populates the $_SESSION superglobal with the result. 
session_decode($enc);

echo "The repopulated current session : ";
var_dump($_SESSION);
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).