I am having a lot of difficulty using cookies with curl. I am trying to create a function that uses CURL to log into a site and sets the session cookie using the CURLOPT_COOKIEJAR
. I am having a lot of difficulty accomplishing this. When I go to c:/var/cookie.txt
, no cookie file is created.
I appreciate any suggestions as to why this is, thanks in advance!
function loginAndGetCookie(){
$ch = curl_init();
$fields = getPostData();
$fields_string = getFieldsString();
$url = 'https://account.site.com/Account/Login.aspx';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'c:\var\cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'c:\var\cookie.txt');
curl_setopt($ch, CURLOPT_URL, $url);
$content = curl_exec($ch);
echo htmlentities($content);
curl_close($ch);
}
loginAndGetCookie();
I am having a lot of difficulty using cookies with curl. I am trying to create a function that uses CURL to log into a site and sets the session cookie using the CURLOPT_COOKIEJAR
. I am having a lot of difficulty accomplishing this. When I go to c:/var/cookie.txt
, no cookie file is created.
I appreciate any suggestions as to why this is, thanks in advance!
function loginAndGetCookie(){
$ch = curl_init();
$fields = getPostData();
$fields_string = getFieldsString();
$url = 'https://account.site.com/Account/Login.aspx';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'c:\var\cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'c:\var\cookie.txt');
curl_setopt($ch, CURLOPT_URL, $url);
$content = curl_exec($ch);
echo htmlentities($content);
curl_close($ch);
}
loginAndGetCookie();
0 commentaires:
Enregistrer un commentaire