Home >php教程 >php手册 >PHP session_encode()和 session_decode()

PHP session_encode()和 session_decode()

WBOY
WBOYOriginal
2016-05-25 16:48:12965browse

本文章来给大家介绍PHP session_encode()和 session_decode() 用法,有需要了解的同学可参考本实例.

session_encode

session_encode — 将当前会话数据编码为一个字符串

说明:

string session_encode ( void ) 

session_encode()返回一个字符串,该字符串包含有被编码的当前会话数据.

实例代码如下:

<?php
//boolean session_encode()
session_register(&#39;bgcolor&#39;);
session_register(&#39;fontcolor&#39;);
$id = session_id($usr_id);
$bgcolor = "white";
$fontcolor = "blue";
$usr_data = session_encode();
print $usr_data;
?>

session_decode

实例代码如下:

<?php
session_start();
$_SESSION = array();
session_decode("products|a:2:{i:0;s:8:\"Hal 2000\";i:1;s:6:\"Tardis\";}");
foreach ($_SESSION[&#39;products&#39;] as $p) {
    print "$p<br/>\n";
}
?>


文章地址:

转载随意^^请带上本文地址!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn