O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Cookies

Set cookies using the setcookie() function. This function has a lot of parameters.

setcookie($name,[$value,$expire,$path,$domain,$secure])

What do those brackets ([]) in the function declaration mean? Take a look at the setcookie() function. When a parameter is enclosed by brackets in a declaration like this, the parameters are optional. If you would prefer to leave them as they are by default, you can do that. In addition, be careful when defining only some of the default values. If you want to change the $secure parameter, but not the $path parameter, you still have to set $path. This is because you can only set the parameters from left to right—you cannot skip any. You must set $name first, $value second, $expire third, and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required