Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a cookies parameters in PHP?

How do you get a cookies params? The "expire, secure, httponly" etc.
Is it possible?

like image 958
turbod Avatar asked Jul 04 '10 08:07

turbod


People also ask

How we can get the cookie values in PHP?

Accessing Cookies ValuesThe PHP $_COOKIE superglobal variable is used to retrieve a cookie value. It typically an associative array that contains a list of all the cookies values sent by the browser in the current request, keyed by cookie name.

What is Setcookie () function?

The setcookie() function defines a cookie to be sent along with the rest of the HTTP headers. A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too.

What is $_ cookie in PHP?

Cookies are text files stored by a server on the client computer and they are kept of use tracking purpose. PHP transparently supports HTTP cookies. Cookies are usually set in an HTTP header. JavaScript can also set a cookie directly on a browser. Server script sends a set of cookies to the browser.

How can we retrieve information from the specified cookie?

get() The get() method of the cookies API retrieves information about a single cookie, given its name and URL. If more than one cookie with the same name exists for a given URL, the one with the longest path will be returned.


1 Answers

There isn't a way to get when a cookie is set to expire or any of the other parameters you are asking for using PHP. This is because PHP doesn't store anything like that, when you are setting a cookie, you are basically saying to output a header to the browser only once, then it's the job of the client (a browser) to send back the cookie data on each HTTP request. PHP therefore has no reason to retain the data, so it doesn't.

You can of course store when the cookie will expire in another cookie or a file somewhere, if you know where in your code the cookies are being set.

like image 116
Sam152 Avatar answered Sep 23 '22 04:09

Sam152