PHP: session_encode - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

session_get_cookie_params session_destroy

Last updated: Fri, 26 Jan 2007

view this page in

# session_encode

(PHP 4, PHP 5)

session_encode -- Encodes the current session data as a string

## Description

string session_encode ( void )

session_encode() returns a string with the contents of the current session encoded within.

See also session_decode()

add a note User Contributed Notes
session_encode
Onur Yerlikaya < http://www.witkey.org >
18-Jul-2006 08:21
`<?php
session_start();
# boolean type
$_SESSION['logged'] = true;
# string type
$_SESSION['name'] = "Onur Yerlikaya";
# integer type
$_SESSION['age'] = 17;
// logged|b:1;name|s:14:"Onur Yerlikaya";age|i:17;
function readSessions() {
$encodedData = session_encode();
$explodeIt = explode(";",$encodedData);
for($i=0;$i<count($explodeIt)-1;$i++) {
$sessGet = explode("|",$explodeIt[$i]);
$sessName[$i] = $sessGet[0];
if(substr($sessGet[1],0,2) == "s:") {
$sessData[$i] = str_replace("\"","",strstr($sessGet[1],"\""));
} else {
$sessData[$i] = substr($sessGet[1],2);
} // end if
} // end for
$result = array_combine($sessName,$sessData);
return $result;
}
/*
readSessions Func shows encoded data in array
Array
(
[logged] => 1
[name] => Onur Yerlikaya
[age] => 17
)
*/
print_r(readSessions());
?>`
<carlos sica>sica at wnet dot com dot br
05-May-2005 09:19
`session_encode() just return the session dataset in a formatted form
session_start();
$_SESSION['login_ok'] = true;
$_SESSION['nome'] = 'sica';
$_SESSION['inteiro'] = 34;
echo session_encode();
this code will print
login_ok|b:1;nome|s:4:"sica";inteiro|i:34;`
add a note
session_get_cookie_params session_destroy

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST