Archivi categoria: PHP

PHP cURL – keep php session during a cUrl request over https

$url =’https://xxx.domain.com/myscrip_with_session_check.php’;
$ch = curl_init();
$strCookie = ‘PHPSESSID=’ . $_COOKIE[‘PHPSESSID’] . ‘; path=/’;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// here i add this two lines because i call a script over https with fake ssl certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

// end ssl hack
curl_setopt($ch, CURLOPT_COOKIE, $strCookie);

//important is to unlock with

session_write_close();
$result = curl_exec($ch);

var_dump(curl_getinfo($ch));

if ($errno = curl_errno($ch)) {
$error_message = curl_strerror($errno);
// echo “cURL error ({$errno}):\n {$error_message}”;
}
curl_close($ch);

var_dump($result);