写cookie的value的时候,看了下google和baidu的cookie文件,里面的value是一长串字符.于是写了个安全字符串类来产生安全字符串. 这个是security.php ?php/** * * @title 安全字符串类 * @author rainysia * @version 1.0.0 * @copyright rainysia, 2012-07-05
写cookie的value值的时候,看了下google和baidu的cookie文件,里面的value是一长串字符.于是写了个安全字符串类来产生安全字符串.
这个是security.php
<?php /** * * @title 安全字符串类 * @author rainysia * @version 1.0.0 * @copyright rainysia, 2012-07-05 18:47:13 星期四 * @package default * @link_me * * **/ /** * @产生随机字符类 * @参数: len 为自定义的字符长度 * @使用: 实例化该类既可 * $www = new genRandomString(); * $www->len='40'; * echo $www->provideRandString(); * unset($www); */ class genRandomString{ public function provideRandString(){ $chars = array('a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','_','#','@','%','&','!'); $charsLen = count($chars) - 1; shuffle($chars); $grs = ""; $len = ""; for ($i = 0; $i len; $i++) { $grs .= $chars[mt_rand(0,$charsLen)]; } return $grs; } } ?>
然后在登录页面的提交按钮后,写这样一段php
<?php if(!isset($_COOKIE['WEB_TITLE'])){ $cookievalue = new genRandomString(); $cookievalue->len='20'; $s = $cookievalue->provideRandString(); setcookie("WEB",$s,time()+10803,"/") or die ("客户端禁止cookie"); }else{ echo "欢迎回来"; } ?>
登录时产生一个cookie文件.里面的$value即为这个类生成的.