php
PHP - 쿠키 생성 클레스
쿠키 생성 클레스입니다. 보통 쿠키는 30개 라는 제한 내에서 만들 수 있지만 다음 클레스를 이용한다면 한개의 쿠키가 5000자를 넘지 않는다면 무한정 만들어 사용할 수 있는 클레스입니다.
<?php
/*
* cookie.class.php
*/
/*
include('cookie.class.php');
setcookie('쿠키이름', '유지시간', '저장경로');
// 쿠키 굽기
$cookie = new setcookie('my_cookie');
$cookie->put_cookie('my_id', 'habony');
$cookie->put_cookie('my_pw', 'password');
$cookie->put_cookie('my_email', 'hahaha@daum.net');
$cookie->cookie();
// 쿠키 가져오기
echo $cookie->get_cookie('my_email');
// 쿠키 부분 삭제
$cookie->put_cookie('my_email');
$cookie->cookie();
// 쿠키 전체 삭제
$cookie = setcookie('my_cookie');
$cookie->remove_cookie();
*/
class setcookie
{
var $cookie;
var $key;
var $name;
var $expire;
var $path;
function setcookie($name,$expire=0,$path='/')
{
$this->name = stripslashes($name);
$this->expire = addslashes($expire);
$this->path = addslashes($path);
$this->key = md5($this->name);
$this->cookie = unserialize($_COOKIE[$this->key]);
}
function put_cookie($key, $value='')
{
$this->cookie[$key] = rawurlencode(stripslashes($value));
}
function cookie()
{
if(strlen(serialize($this->cookie)) > 5000)
{
return false;
}
else
{
setcookie($this->key, serialize($this->cookie), $this->time(), $this->path());
return true;
}
}
function get_cookie($key)
{
return rawurldecode($this->cookie[$key]);
}
function time()
{
return $this->expire;
}
function path()
{
return $this->path;
}
function remove_cookie()
{
$this->cookie = false;
$this->expire = $this->time()-42000;
$this->cookie();
}
}
?>
0 댓글