tags:

views:

922

answers:

3

Are there any helper libs to read a cookie file in php. I have a cookie file on my local disk and I would like a better way of reading it. I am currently just reading to file like by line and parsing out the values.

+1  A: 

I think $_COOKIE is what your looking for.

This superglobal can be used to read cookie data... to set it you need to use setcookie() More can be found on the PHP website under $_COOKIE superglobal

null
+1  A: 

I'm not sure I understand you correctly as it's normally pretty straightforward to set (using setcookie) and read a cookie in PHP from your scripts:

$value = $_COOKIE['mycookie'];

If you are looking for a way of reading a raw cookie directly from your filesystem, without going through a browser, you'll need to specify what format/browser they were written in. The values could have been serialized from a lot of different languages and the end-result of the file might differ from browser to browser.

// Edit:

More on the browser differences: for example, Mozilla has a format like that and IE something more like that.

lpfavreau
A: 

If you are using sessions in PHP, and you are in fact trying to parse the session data on disk, you can use the unserialize() function on the contents of that file.

ahc