Cookie Components in PHP A cookie is sent from the server to the browser as part of the HTTP headers.
Here we will illustrate an example of an HTTP header to create a cookie:
Set-Cookie: fontSize=3; expires=saturday, 9-May-2015 17:53:08 GMT; path=/; domain=.example.com; HttpOnly
Here, we will describe you all the information contained in the cookie.
|name(for example, fontSize )||The name field describes the name of the cookie.|
|value (for example, 3 )||The value field describes the value of the cookie.|
|expires||The expire field describes the time at which the cookie will expire. When the expire time is reached at its point then, it will be deleted from the browser, and is no longer sent back to the server in requests. If the value of expire field is set to zero, or omitted, the cookie lasts as long as the browser is running, and is automatically deleted when the browser exits.|
|path||The path field describes the path that the browser should send the cookie back to. If specified, the browser will only send the cookie to URLs that contain this path.|
|domain||By default, a browser only sends a cookie back to the exact computer that sent it.|
|secure||If the secure field is present then it indicates that the cookie should be sent only if the browser has made a secure (https) connection with the server and if the secure field is not present, then the browser will send the cookie to the server regardless of whether the connection is secure. Ignore this field if you are working with standard (http) connections.|
|HttpOnly||If the HttpOnly field is present then it tells the browser that it should make the cookie data accessible only to scripts that run on the Web server (that is, via HTTP).|