cookie是发送在浏览器端一个小小的文件,可用来记录用户操作过的记录,如访问了那些文件等.
写入cookie实例代码如下:
- setcookie(name, value, expire, path, domain);
- function w_cookie($n, $c, $e = 0,$isdes=1)
- {
- if($isdes==1){$c=endes($c,deskey);}
- $exp = time() + 3600 * 24 * 30;
- if($e == 0)
- {
- setcookie($n, $c, $exp,"/");
- }
- else
- {
- setcookie($n, $c,0,"/");
- }
- }
关闭cookie方法就是把它设置过期即可.
实例代码如下:
- function cookie($var, $value='', $time=0, $path='', $domain=''){
- $_COOKIE[$var] = $value;
- if(is_array($value)){
- foreach($value as $k=>$v){
- setcookie($var.'['.$k.']', $v, $time, $path, $domain, $s);
- }
- }else{
- setcookie($var, $value, $time, $path, $domain, $s);
- }
- }
-
-
-
- cookie("website","安卓主题","./","www.111cn.net");
-
防止重复提交实例代码如下:
- $time = time() + 300;
- $code = md5($string . $time . $salt);
- setcookie('check_time', $time);
- setcookie('code', $code);
-
- $TIME = time();
- if($check_time < $TIME)
-
-
- if(md5($string . $check_time . $salt) !== $code)
|