Try as I might, I am unable to get curl to pass the PHPSESSID
cookie. I have a similar setup to what several others have described, but I haven't been able to get any of the proposed solutions working.
I have a page that sends a get request to pageA.php
. pageA.php
needs some information from pageB.php
, which is on another server, so I am using curl. pageB
maintains the session state that I need to get to and from my page.
I am able to pass other cookies from pageA
to pageB
, just not the PHPSESSID
cookie.
The following works (a cookie arrives on pageB
):$options[CURLOPT_COOKIE] = "myPHPSESSID=" . $sessionId;
The following does not:
$options[CURLOPT_COOKIE] = "PHPSESSID=" . $sessionId;
(I build an $options array and then pass it to curl_set_opt_array
)
In fact, the latter causes some sort of error that I am unable to discern, as my call to curl_exec
never returns (and pageB
is never reached).
I've tried setting the header instead of using CURLOPT_COOKIE, but also with no success:
$options[CURLOPT_HTTPHEADER][] = "Cookie: myPHPSESSID=" . $sessionId;
the above works just fine but
$options[CURLOPT_HTTPHEADER][] = "Cookie: PHPSESSID=" . $sessionId;
does not.
PHP evidently does not want me to manually set PHPSESSID. I'm not sure if it's relevant, but at no time on pageA do I call start_session()
(though I tried doing so and had the same results).
I realize I could (probably) just pass the session id as a differently-named cookie and have pageB call set_session_id()
or something similar. But I really want to know why what I'm doing is not working, as I'd rather fix what I'm doing wrong than create a workaround. I can provide some dumps of the various headers that are pinging around if that's helpful, but I figure this question is long enough for now.
Thanks...