You are here

Creating, checking and removing cookies

Creating:

setcookie('cookie-name', 'cookie-value',  0, '/');

Checking:

isset($_COOKIE['cookie-name']);

Removing:

setcookie('cookie-name', null, -1, '/');

Using Javascript:

                var now = new Date();
                var time = now.getTime();
                var expireTime = time + 1000*10; //expire in 10 seconds
                now.setTime(expireTime);
                var tempExp = 'Wed, 31 Oct 2012 08:50:17 GMT';
                document.cookie = 'cookie=ok;expires='+now.toGMTString()+';path=/';
code type: