i have a simple function i used to use to do login remotely to other websites using curl and php
this is the function
public function Curllogin($url,$data,$proxy,$proxystatus)
{
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR,$this->SetCookieFile);
curl_setopt($login, CURLOPT_COOKIEFILE,$this->SetCookieFile);
curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($login, CURLOPT_TIMEOUT, 40);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'on') {
curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($login, CURLOPT_PROXY, $proxy);
}
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_HEADER, TRUE);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($login, CURLOPT_POST, TRUE);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
ob_start(); // prevent any output
return curl_exec ($login); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($login);
unset($login);
}
its working with no problem to login
but there a small problem i found
lets say im log in to example.com and passed the username and password within the $data variable
it will login with no problem
but when changing the $data values using another username and password it’s logging me in with the old username and password which used for last login
ignoring the new login information
i tried every thing like deleting the cookies.txt file and let the script re-create it
i even tried to clear my browser cached cookies
but it won’t change it to use the new data
each time it use the first username and password which i used to login
is there any function to destroy the cookie made by the CURL or do i miss something?
Just change your
$this->SetCookieFileto an empty file, possibly a random file in the temp directory. Your “real” browser’s cookies don’t have anything to do with this, cURL is managing cookies separately from that.