send session var with php cUrl send session var with php cUrl curl curl

send session var with php cUrl


I believe you're looking for CURLOPT_COOKIE

curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());


In script 1 you could use CURLOPT_COOKIE if you keep track of the session ID from the response yourself.

I don't think you need or want session_start in script 1 if it is going to be making multiple requests to myscript.php that creates a session.

Use this in script 1:

curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt'); // set cookie file to given filecurl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt'); // set same file as cookie jar

And then make your request as normal. Any cookies set by myscript.php will be saved to the cookie jar file when the request completes, the cookiefile will be checked for any cookies to be sent prior to sending the request.

You could manually track the php session cookie from the curl request and use CURLOPT_COOKIE as well.


You miss one option parameter for using post. Please add this one, it should work:curl_setopt($ch, CURLOPT_POST, true);