PHP » Cookies and Sessions » session_decode()

Syntax:
string session_decode(string session data)
data
The string of encoded session data.

Decodes session data.

This function decodes session data that has been previously encoded using session_encode().

Examples

Code:
<?php

// resume the session
session_start();

// connect to database and fetch data for session
mysql_connect("localhost", "www", "www") or die("Could not connect");
mysql_select_db("phpsample") or die ("Could not select db");
$query = "SELECT data FROM sessions WHERE sid = '" . session_id() . "'";
$result = mysql_query($query) or die ("db query failed");
$session_data = mysql_result($result, 0, 'data');

// decode and print session data
session_decode($session_data);
print "Decoded session data for session " . session_id() . ": " . $_SESSION["myvar"];

?>
Output:
Decoded session data for session 1979d74b7c83d8ba0b1cc5f84b938f6f: Hello world!
Explanation:

Decodes session data saved in a database. Use together with the code sample for session_encode()

See Also: