5
I see some frameworks, CMS and the like, writing cookies directly in PHP with setcookie
and others stock to send us headers
at the end of the run. I wanted to know how to create a pattern for the creation of cookies.
PHP
The setcookie() function sets a cookie to be sent along with the rest of the HTTP headers
We should create by sending by header?
header( "Set-Cookie: {$name}={$value};" )
Or leave it to PHP?
setcookie( $name , $value )
I recommend using setcookie() as it is an appropriate function to do this type of action. Header() is also good, but we recommend using setcookie()
– Alisson Acioli
Another thing (that by now you should know) is that with
header
would have to useurlencode
orrawurlencode
. The following code is available on Github: https://github.com/php/php-src/blob/71c19800258ee3a9548af9a5e64ab0a62d1b1d8e/ext/standard/head.c#L80– Guilherme Nascimento
@Guilhermenascimento, I didn’t know that. He would have to use
domain
?– Papa Charlie
@Papacharlie then by what I analyzed from php source code it is necessary only name and value to be encoded, others not.
– Guilherme Nascimento