views:

72

answers:

2

Hello fellow Overflows!

I'm writing an "API" for a website which doesn't have it.

Basically, my PHP code logs into the website and grabs the data I need (two different transfers).

At login time, I'm getting a bit of a problem. The website sets a couple of cookies through HTTP, which I'm capturing using CURL's cookie mechanism. This seems to work out nicely, except that they are also trying to set a cookie via javascript in that same response.

I don't need to parse the javascript since the cookie they set is entirely predictable. What I need is to somehow tell CURL that this cookie exists, WHILE it stills maintains the other cookies.

Help? :)


After submitting the login details via curl POST, I get to these headers:

HTTP/1.1 200 OKDate: Fri, 20 Aug 2010 09:39:14 GMT
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 492
Set-Cookie: JSESSIONID=5DE1F32B3668DABB408BBEA10C28DBD5.testmmf1; Path=/merchantlogin
Set-Cookie: loginType=M
Connection: close

And this is the page content:

<script type="text/javascript">
    var nextyear = new Date();
    nextyear.setFullYear(nextyear.getFullYear() + 1);
    document.cookie = 'login=' + document.referrer + '; expires=' + nextyear.toGMTString();
</script>

Notice the Set-Cookie and document.cookie parts.

A: 

Generate cookie file via code, and before making request to location witch requires that cookie add it simply through setopt with option CURLOPT_COOKIEFILE

canni
I think I'm fixing this just like that...
Christian Sciberras
You can mix up things, receive first cookie, merge it with generated one, and with next request send merged cookie
canni
A: 

You could set the cookie using curl_setopt and the CURLOPT_COOKIE option first. Of course doing this will erase your other cookies, but they'll be gotten back, right?

If you could get a hold of the current value of CURLOPT_COOKIE, you could append your cookie with a semicolon. But PHP doesn't seem to have a curl_getopt function.

Borealid
As I said above, the issue is to send the existing cookies at the new one, at the same time, to the target server.
Christian Sciberras