Jump to content

cURL AutoLogin


Garethp

Recommended Posts

Ok, so I'm trying to AutoLogin with my account on a site called GaiaOnline. I can't remember why I started (it was 3 in the morning) but now it's turned into a kind of an annoying pest to me. Everytime I try to login, it says that "The information you submitted is incorrect. Are you sure you have cookies enabled?" which is different to the message it gives for incorrect username and password. Here's my code

 

<?php
$POST = array
(
'username'=>'',
'password'=>'',
'redirect'=>'http://www.gaiaonline.com/mygaia/',
'token'=>'958394166.1270267057.1394276344',
'sid'=>'d31e9335esyix02kvvbu00antruebzd0',
'signInButton'=>'Log In',
);

$URL = 'http://www.gaiaonline.com/auth/login/';
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; 

$vars = "";

foreach($POST as $k=>$v)
{
$vars .= "$k=$v&";
}

$ckfile = "cookie.txt";

$ch = curl_init ("http://gaiaonline.com/");
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);

$ch = curl_init($URL);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $vars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_REFERER, 'http://gaiaonline.com/');
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
$store = curl_exec ($ch);
$info = curl_getinfo($ch);

$store = htmlentities($store);

// CLOSE CURL
curl_close ($ch);

echo "<pre>$store</pre>";

?>

 

Ofcourse I enter my username and password. $POST is an array that contains all the same post information that is given by their login form. I'm not sure where I'm going wrong. I have a useragent, and a cookie file (which exists, but for some reason it's always empty) and I've even got the script visiting home page to collect the cookies a normal user would before logging in. I don't suppose anyone has any feedback?

Link to comment
https://forums.phpfreaks.com/topic/197438-curl-autologin/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.