Search code examples
phpcookiessetcookie

PHP: cookies via path/domain


Is it possible to set the path and domain one time at the beginning of the script and have all future sets conform to the same?

From the docs:

 bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )

Solution

  • sure:

    function own_setcookie($name, $value, $expire=0) {
        setcookie($name, $value , $expire, 'myPath', 'myDomain');
    }
    

    then use:

    own_setcookie('myName', 'myValue');