I have been able to use my current session in the process created by my curl request using the following code -
$query = http_build_query(array(
"pcode"=>strtolower($code)
));
$url = $_SERVER['REQUEST_SCHEME'].":".PUBLIC_ROOT."xyz.php"."?".$query;
session_write_close();
$curl = curl_init($url);
$useragent = $_SERVER['HTTP_USER_AGENT'];
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_GET, true);
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
curl_setopt($curl, CURLOPT_COOKIE, $strCookie );
$json_response = curl_exec($curl);
curl_close($curl);
I used the following answer for the above code - https://stackoverflow.com/a/15374966/815929
Now the issue is that in the new process (created by the curl request), I need to set some session variables. However these session variables do not reflect in the calling process after curl_close()
.
I had some session vars in my calling script. I was able to use these session vars in the new process started by the curl request. This new process also set some new session vars. However when we are back to the calling process these new session vars are not reflected.
Are there additional curl options that I need to set to make this work?