PHP (setcookie) vs header (header)

Posted on

Coding Problem :

I see some frameworks, CMS and the like, write cookies directly in PHP with setcookie and others stock to emit in headers at the end of execution. I would like to know how to create a pattern for creating cookies.

  

PHP

  
  

The setcookie () function sets a cookie to be sent along with the rest of the HTTP headers

Should we create by sending by header?

header( "Set-Cookie: {$name}={$value};" )

Or is it PHP?

setcookie( $name , $value )

    

asked by anonymous 30.07.2014 / 09:39

Answer :


Answer 1 :

Both functions get the same result.

But what sets setcookie() apart is its ease of creation of more complex cookies, with expiration date, domain of the application that the cookie will be used (www.algumacoisa.com.br), among others.

See all the parameters that the function accepts:

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

More information on the php documentation .

    


Answer 2 :


Answer 3 :


Answer 4 :


Answer 5 :


Answer 6 :


Answer 7 :


Answer 8 :


Answer 9 :

Leave a Reply

Your email address will not be published.