So I'm using cURL to log into a website here, and spoofing the user agent. I have two constants: one called IOS
that is an iOS user agent, and one called CHROME
that is a Chrome user agent. Here is the code to log in:
public function signIn($username, $password)
{
$url = "https://www.site.net/post/Index.page";
$cookie = "cookie.txt";
$postdata = "screenName=$username&kclq=$password&submitEvent=1&TCNK=authenticationEntryComponent&enterClicked=true&ajaxSupported=yes";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, IOS);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_REFERER, "https://www.site.net/Index.page");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
curl_close($ch);
}
In subsequent requests, I would like to change the user agent from IOS
to CHROME
, and it doesn't seem to work (I change to CHROME
and the website still serves up a mobile page). When I run this request:
curl -L -X POST -b "cookie.txt" --user-agent " . CHROME . " https://site.net
It does not serve up a desktop site, but a mobile one. Is it possible to change the user agent while logged in?