Hi.
It's best practice (speed/flexibility as well) using an approach
like this for instance:
<?php
class _Cookie
{
public static function setCookie($cookieName,$cookieValue,$expiry)
{
if(!isset($_COOKIE[$cookieName]))
{
setcookie($cookieName, $cookieValue, time()+$expiry);
}
}
public static function deleteCookie($cookieName,$expiry)
{
if(isset($_COOKIE[$cookieName]))
{
setcookie ($cookieName, "", time()-$expiry);
unset($_COOKIE[$cookieName]);
}
}
}
?>
or
<?php
function set_Cookie($cookieName,$cookieValue,$expiry){
if(!isset($_COOKIE[$cookieName])){
setcookie($cookieName, $cookieValue, time()+$expiry);
}
}
function deleteCookie($cookieName,$expiry){
if(isset($_COOKIE[$cookieName])){
setcookie ($cookieName, "", time()-$expiry);
unset($_COOKIE[$cookieName]);
}
}
?>
Thanks in advance.
Bye.I'd go with the OO method unless it's a simple little script that you're sure you'll never want to re-use with other applications at some point.
It's best practice (speed/flexibility as well) using an approach
like this for instance:
<?php
class _Cookie
{
public static function setCookie($cookieName,$cookieValue,$expiry)
{
if(!isset($_COOKIE[$cookieName]))
{
setcookie($cookieName, $cookieValue, time()+$expiry);
}
}
public static function deleteCookie($cookieName,$expiry)
{
if(isset($_COOKIE[$cookieName]))
{
setcookie ($cookieName, "", time()-$expiry);
unset($_COOKIE[$cookieName]);
}
}
}
?>
or
<?php
function set_Cookie($cookieName,$cookieValue,$expiry){
if(!isset($_COOKIE[$cookieName])){
setcookie($cookieName, $cookieValue, time()+$expiry);
}
}
function deleteCookie($cookieName,$expiry){
if(isset($_COOKIE[$cookieName])){
setcookie ($cookieName, "", time()-$expiry);
unset($_COOKIE[$cookieName]);
}
}
?>
Thanks in advance.
Bye.I'd go with the OO method unless it's a simple little script that you're sure you'll never want to re-use with other applications at some point.