I have developed a small php script using cURL to automate my daily logging activity to my company's site(that records my check-in time.) It uses cookies.
The site sets some cookies before and after I login and these cookies interact
to track my login and sends a response to main server.
Here is the code I am using
$cookie_file_path = "cookies.txt";
$url = "http://www.company.com/user/";
// www.company.com sets a cookie and redirects to www.companysite.com/login/
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
ob_start(); // prevents output
curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
The above code simulates me visiting the login website and the corresponding cookies are stored in cookies.txt
Now I am going to post my login info using the below code
unset($ch);
$POSTFIELDS = "name=myname&pass=mypass";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_URL,"http://www.companysite.com/login/process.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec ($ch); // execute the curl command
curl_close ($ch);
This code above logs me into the site and the cookies from www.companysite.com/user/login/process.php are also stored in cookies.txt
But unfortunately my company again places a small pixel in the resulting site
that searching for the first cookie set and then sends info to www.company.com/track.php that I have logged in.
Company.com(sets a cookie named user_id) >> Redirects to CompanySite.com
CompanySite.com(after logging in) >> Pixel from Company.com searches for cookie called user_id set before posting the form
All the cookies are set in cookies.txt but the last tracking part alone in not working.
But the last part is not working..
so how do I use cURL to solve this ??
Please help