[php] serialize, unserialize the session data in PHP
functionality, you will see the they are not going as you think. So here, i find these two functionality which will help you to do that.
/* *
* serialize session
*
* @param array $data
* @param boolean $safe
* @return string
*/
function serialize_session( $array, $safe = true)
{
// the session is passed as refernece, even if you dont want it to
if ( $safe)
{
$array = unserialize( serialize( $array));
}
$raw = '';
$line = 0;
$keys = array_keys( $array);
foreach ( $keys as $key)
{
$value = $array[ $key];
$line++;
$raw .= $key . '|';
if ( is_array( $value) && isset( $value['huge_recursion_blocker_we_hope']))
{
$raw .= 'R:' . $value['huge_recursion_blocker_we_hope'] . ';';
}
else
{
$raw .= serialize( $value);
}
$array[ $key] = Array('huge_recursion_blocker_we_hope' => $line);
}
return $raw;
}
/* *
* unserialize session
*
* @param string $data
* @return array
*/
function unserialize_session( $data)
{
$vars = preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/', $data, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
for ( $i = 0; $vars[ $i]; $i++)
{
$result[ $vars[ $i++]] = unserialize( $vars[ $i]);
}
return $result;
}
上一篇: PHP+MySQL 购物车程序实例
下一篇: Bume in MySQL_MySQL
推荐阅读
-
[php] serialize, unserialize the session data in PHP
-
PHP通过session id 实现session共享和登录验证的代码_PHP教程
-
PHP保存session到memcache服务器的方法,sessionmemcache_PHP教程
-
php session_start()关于Cannot send session cache limiter
-
将PHP的session数据存储到数据库中的代码实例_php实例
-
php session 检测和注销_PHP
-
PHP Session 用法与Sessions入实例应用
-
ThinkPHP关于session的操作方法汇总_PHP
-
php session 检测和注销_php基础
-
PHP中使用Session配合Javascript实现文件上传进度条功能_php技巧