Search code examples
phpcookiessetcookie

Set cookie with path but no expiration date?


I want to setCookie with path but no expiration date. But the syntax is like this in PHP setCookie(name,value,exp-date,path) I want setCookie(name,value,path) but the PHP wount let me. Or I want to expiration be Session. How its posible?


Solution

  • The setCookie function requires an expiration date, just set it to a far future date such as ten years:

    time() + (10 * 365 * 24 * 60 * 60)

    If you just want to use session variables, use this example:

    http://www.w3schools.com/php/php_sessions.asp

    To have the cookie end at the end of the session, use zero for time.

    setcookie('COOKIENAME', 'COOKIEVALUE', 0, '/mypath');