1

I am trying to parse the response header cookies for a GET request.

For some reason, getCookies() is empty! I get a 200 Response but for some reason cannot access the cookies. I'm able to get the headers, though.

Is it possible this website is hiding its cookies? What are some ways to retrieve hidden cookies?

$request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$request2 = new HTTP_Request2($newUrl, HTTP_Request2::METHOD_POST);

$response = $request->send();

foreach ($response->getCookies() as $c)
{
   request2->addCookies($c['name'], $c['value']);
}

Cookies are being set with Javascript via (I peeked into their JS code)

<script language="JavaScript">
document.cookie="MRHCId="+Math.round((new Date()).getTime()/1000)+"_0_3600; path=/"; 
</script>

How can I send this cookie along with my PHP Post request?

tereško
  • 58,060
  • 25
  • 98
  • 150
Mark Kennedy
  • 1,751
  • 6
  • 30
  • 53
  • You are obviously using some framework. What is it? – tereško Oct 01 '13 at 23:33
  • Is it possible that the website doesn't use cookies? They are not required for a website to operate or anything. Or perhaps, it just doesn't set them through the headers? They can be set through javascript. And I wouldn't be surprised with all the JS heavy websites out there. Also, there is no such thing as a "Hidden Cookie". – Jonathan Kuhn Oct 01 '13 at 23:40
  • @tereško http://pear.php.net/manual/en/package.http.http-request2.php – Mark Kennedy Oct 01 '13 at 23:45
  • @JonathanKuhn Yes, I found out they are being set with JavaScript. How can I obtain the cookies, accounting for this? – Mark Kennedy Oct 01 '13 at 23:46
  • Unless you can parse the javascript (like a browser), you can't. You could search the javascript for all "document.cookies" and try to manually parse what they are setting. Chances are they are setting the cookies using a library (jquery/plugin) that abstracts the setting of cookies. In that case they would have some function that they call you could look for then once again parse manually. – Jonathan Kuhn Oct 01 '13 at 23:49
  • You would have to look at the source to see how/where they are setting the cookie in javascript, use php string functions to find that part and parse the cookie manually. It can all be a pain though. – Jonathan Kuhn Oct 01 '13 at 23:50
  • @JonathanKuhn There is only one cookie being set, and it's a relatively simple time stamp. I've updated their cookie calculation logic in my question. Can't I just replicate the logic with PHP and then send it along via request2->addCookies()? – Mark Kennedy Oct 01 '13 at 23:50
  • Depending on the what the timestamp represents, you might just be able to use php to generate a new timestamp with `time()` and add that. If you need the actual timestamp from the page, you should be able to `->getBody()` and look for where the timestamp is being set (in php), get the timestamp using regular expressions or some string parsing functions and use `addCookie` to send it with your next request. – Jonathan Kuhn Oct 01 '13 at 23:54
  • @JonathanKuhn It worked. I had to replicate the JavaScript cookie logic in PHP. Thanks for the suggestion! – Mark Kennedy Oct 02 '13 at 17:49

1 Answers1

0

Posting my comment as an answer in case you want to close the question:

Is it possible that the website doesn't use cookies? They are not required for a website to operate or anything. Or perhaps, it just doesn't set them through the headers? They can be set through javascript. And I wouldn't be surprised with all the JS heavy websites out there. Also, there is no such thing as a "Hidden Cookie".

Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43