tags:

views:

494

answers:

3

Hi

I'm making a php script that would work like API on site that dosn't provide one. I'm using curl for it and the site is posting cookies with javascritpt, so i can't read them.

Is there a php class or php module that would read javascript, store the cookie and let me resubmit it with curl to the mentioned page?

I Red somehwer that its possible to read php from Java, so maybe there is a similiar way for JS/PHP?

+2  A: 

Your best bet is to try and read the cookie from php. Javascript can't talk to php itself, but php can grab a cookie that javascript has created.

http://php.net/manual/en/features.cookies.php goes on to say:

Any cookies sent to you from the client will automatically be included into a $_COOKIE auto-global array...

Hope this helps!

darkAsPitch
Or you might be looking for http://www.php.net/manual/en/function.setcookie.php
darkAsPitch
A: 

It sounds like your script will be "between" the site and the client? eg. the client calls your API, and you log into the site pretending to be a client, then pass back the results?

If so, then all cookies that the site sets will come back through the headers of the page. You can access these by calling

curl_setopt($handle, CURLOPT_HEADER, true);

before you request the page. When you get the returned page, it will have the HTTP headers on the start of it. You can then search the header for any "set-cookie" lines, and they will contain the details of the cookie that the site is trying to send the client.

Nick
+1  A: 

You need to check the logic of the javascript which writes the cookie and try to replicate it using php. The server will not be able to verify if the cookie has been set by your script or the javascript because the javascript is working on the clientside .

Michael