-
Notifications
You must be signed in to change notification settings - Fork 0
/
jiami.php
44 lines (35 loc) · 1.22 KB
/
jiami.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
session_start();
//假设用户登录成功获得了以下用户数据
$userinfo = array(
'uid' => 10000,
'name' => 'spark',
'email' => '[email protected]',
'sex' => 'man',
'age' => '18'
);
header("content-type:text/html; charset=utf-8");
/* 将用户信息保存到session中 */
$_SESSION['uid'] = $userinfo['uid'];
$_SESSION['name'] = $userinfo['name'];
$_SESSION['userinfo'] = $userinfo;
echo "welcome ".$_SESSION['name'] . '<br>';
//* 将用户数据保存到cookie中的一个简单方法 */
$secureKey = '1111111111111111'; //加密密钥
$str = serialize($userinfo); //将用户信息序列化
echo "用户信息加密前:".$str;
$str = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secureKey, $str, MCRYPT_MODE_ECB));
echo "用户信息加密后:".$str;
//将加密后的用户数据存储到cookie中
setcookie('userinfo', $str);
//当需要使用时进行解密
$str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $secureKey, base64_decode($str), MCRYPT_MODE_ECB);
$uinfo = unserialize($str);
echo "解密后的用户信息:<br>";
var_dump($uinfo);
// setcookie('test', time());
// setcookie('test1', 1, 0);
//在这里试着删除test的cookie值
setcookie('test',time()-1);
var_dump($_COOKIE);
?>