쿠키 처리를 위한 PHP 클래스
풀어 주다: 2016-07-25 08:43:13
-
- 登录
- 注册
- 订阅RSS
- 网站地图
- 脚本分享网
- // cookieClass
- // Copyright (C) 2005 JRSofty Programming.
- // http://jrsofty1.stinkbugonline.com
- // Licensed under GNU/GPL
-
- class cookieClass{
-
- var $cName = '';
- var $cTime = '';
- var $cSerialize = false;
- var $cPath = '';
-
- function cookieClass($cookieName, $cookieTimeout, $cookieSerialize = false, $cookiePath = "/"){
- $this->cName = $cookieName;
- $this->cTime = $cookieTimeout;
- $this->cSerialize = $cookieSerialize;
- $this->cPath = $cookiePath;
- // This should fix the issue if you have cookies set and THEN turn on the serialization.
- $iname = $this->cName . "_S";
- if($this->cSerialize && !isset($_COOKIE[$iname])){
- $cookArr = array();
- foreach($_COOKIE as $name=>$val){
- if(strpos($name,$this->cName) !== false ){ // make sure it is a cookie set by this application
- $subname = substr($name,strlen($this->cName) 1);
- $cookArr[$subname] = $val;
- $this->KillCookie($name);
- }
- }
- $this->WriteCookie($cookArr);
- }
- // This is the opposite from above. changes a serialized cookie to multiple cookies without loss of data
- if(!$this->cSerialize && isset($_COOKIE[$iname])){
- $cookArr = unserialize($_COOKIE[$iname]);
- $this->KillCookie($iname);
- $this->WriteCookie($cookArr);
- }
-
-
- }
-
- function DestroyAllCookies(){
- foreach($_COOKIE as $name=>$val){
- if(strpos($name,$this->cName) !== false){
- $_COOKIE[$name] = NULL;
- $this->KillCookie($name);
- }
- }
- }
-
- function ReadCookie($item){
- if($this->cSerialize){
- $name = $this->cName . "_S";
- if(isset($_COOKIE[$name])){
- // handle the cookie as a serialzied variable
- $sCookie = unserialize($_COOKIE[$name]);
- if(isset($sCookie[$item])){
- return $sCookie[$item];
- }else{
- return NULL;
- }
- }else{
- return NULL;
- }
- }else{
- $name = $this->cName . "_" . $item;
- if(isset($_COOKIE[$name])){
- // handle the item as separate cookies
- return $_COOKIE[$name];
- }else{
- return NULL;
- }
- }
- }
-
- function KillCookie($cName){
- $tStamp = time() - 432000;
- setcookie($cName,"",$tStamp,$this->cPath);
- }
-
- function WriteCookie($itemArr){
- if($this->cSerialize){
- $sItems = serialize($itemArr);
- $name = $this->cName . "_S";
- $_COOKIE[$name] = $sItems;
- $tStamp = time() $this->cTime;
- setcookie($name,$sItems,$tStamp,$this->cPath);
- }else{
- $tStamp = time() $this->cTime;
- foreach($itemArr as $nam=>$val){
- $name = $this->cName . "_" . $nam;
- $_COOKIE[$name] = $val;
- setcookie($name,$val,$tStamp,$this->cPath);
- }e
- }
- }
-
-
- }
- ?>
复制代码
|
쿠키, PHP
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31