php - Using cURL - maintain cookies & sessions, etc -
say make request log site, using curl.
$ch = curl_init(); curl_setopt($ch, curlopt_url, $urls["sign_in"]); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_cookiejar, "cj.txt"); curl_setopt($ch, curlopt_cookiefile, "cj.txt"); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $pdata); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_referer, $urls["home"]); curl_exec($ch); curl_close($ch);
now, make request page. how can keep same sessions & cookies had (in previous code) alive in next request? tried this, not working:
$ch = curl_init(); curl_setopt($ch, curlopt_url, $urls["enter"]); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_cookiejar, "cj.txt"); curl_setopt($ch, curlopt_cookiefile, "cj.txt"); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_referer, $urls["home"]); $data = curl_exec($ch); curl_close($ch);
btw, in same php file.
any ideas? in advance!
it works me.
check have permission cj.txt
writeable. or, if cj.txt
doesn't exist, make sure have permission create (directory execute permissions, believe).
Comments
Post a Comment