2
Contributors
15
Replies
16
Views
6 Years
Discussion Span
Last Post by anusanker
0

For login on this site, you at begin must parse __VIEWSTATE and __PREVIOUSPAGE variables a then send post request by curl like this:

__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=test&password=test&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2

And don't forget about cookies!

0

Hi ,

I am attaching my code along with this, I also placed the values in the code with respect to your suggestion in the previous post.
The issue is we can login to many other sites with this login curl function. But it doesn't work for this particular site.
I just placed a dummy text in the place of username and password here.
here is the php code:

    $baseurl = "http://www.norskbildelkatalog.no";
    $loginurl = "http://www.norskbildelkatalog.no";
    $userName = "test";             //value of username
    $userPwd = "test";                              //value of password field       
    $loginButton = "";                                      //value of login button
    $userfieldname = "ctl00$tbUserName";                                //name of the field username
    $passfieldname = "ctl00$tbPassword";                                //name of the field password
    $buttonName = "ctl00$btnLogin";                                         //name of the submit button
    //$spiderId = $LoginDetails['idSpiders'];                                           //end values
    $link = "VW";                                                           
    $cookie_file_path = "cookies.txt"; 
    $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
    $reffer = "http://www.norskbildelkatalog.no";


$result_final = curlLogin($loginurl,$userName,$userPwd,$loginButton,$userfieldname,$passfieldname,$buttonName,$cookie_file_path,$agent);
            print_r($result_final);



function curlLogin($loginurl,$userName="",$userPwd="",$loginButton="",$userfieldname="",$passfieldname="",$buttonName="",$cookie_file_path="",$agent=""){
                if($passfieldname!="") {                                 //for sites that have a password field
                        $password = '&' .$passfieldname.'=';
                    $POSTFIELDS = $userfieldname.'='. $userName . $password. $userPwd . '&'.$buttonName.'='. $loginButton.'__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=wEPDwULLTE2OTYxMTQyOTJkZKnDWEWkr2o2KzEZL/UtwkVYytbh&__EVENTVALIDATION='."wEWBAKCiZ7KBAL06sf/AQK/0oqcCQLnrI+ZD94ytl4m3yVK2AjSmUM/lJpk24m3".'&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2';
                }
                //$POSTFIELDS = '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=vwx7a&password=smwhe&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2'; 
                //$ch = curl_init(); 
                $ch = $this->ch;
                curl_setopt($ch, CURLOPT_URL,$loginurl);
                curl_setopt($ch, CURLOPT_USERAGENT, $agent);
                curl_setopt($ch, CURLOPT_POST, 1); 
                curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                curl_setopt($ch, CURLOPT_REFERER, $reffer);
                curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
                curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
                $result = curl_exec ($ch);
                return $result;
                curl_close ($ch); 

    }

Edited by pyTony: fixed formatting

0

No!
You must parse __VIEWSTATE and __PREVIOUSPAGE variables using regular expressions because they will change in next time.

0

I checked the __VIEWSTATE hidden value on different times but seems same on different submission.I think, some times the issue may due to js function while submitting.

0

Hi ,

You can also see my test page and its output in the given url please see this too
And I also placed the cookie variable in code please see. and let me know if any change is needed in the code with sample code

I am attaching my code along with this, I also placed the values in the code with respect to your suggestion in the previous post.
The issue is we can login to many other sites with this login curl function. But it doesn't work for this particular site.

I think the issue is due to the site create an encrepted url for each login, and it is not available on the curl response .


http://autobutler.no/test123.php

here is the php code:

<?php

$value = date("dmhis");
setcookie("Cookie", $value);

$baseurl = "http://www.norskbildelkatalog.no";
$loginurl = "http://www.norskbildelkatalog.no";
$userName = "vwx7a"; //value of username
$userPwd = "smwhe"; //value of password field
$loginButton = ""; //value of login button
$userfieldname = "ctl00$tbUserName"; //name of the field username
$passfieldname = "ctl00$tbPassword"; //name of the field password
$buttonName = "ctl00$btnLogin"; //name of the submit button
//$spiderId = $LoginDetails; //end values
$link = "VW";
$cookie_file_path = "cookies.txt";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
$reffer = "http://www.norskbildelkatalog.no";


$result_final = curlLogin($loginurl,$userName,$userPwd,$loginButton,$userfieldname,$passfieldname,$buttonName,$cookie_file_path,$agent);
print_r($result_final);

function curlLogin($loginurl,$userName="",$userPwd="",$loginButton="",$userfieldname="",$passfieldname="",$buttonName="",$cookie_file_path="",$agent=""){
if($passfieldname!="") { //for sites that have a password field
$password = '&' .$passfieldname.'=';
$POSTFIELDS = $userfieldname.'='. $userName . $password. $userPwd . '&'.$buttonName.'='. $loginButton.'__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=wEPDwULLTE2OTYxMTQyOTJkZKnDWEWkr2o2KzEZL/UtwkVYytbh&__EVENTVALIDATION='."wEWBAKCiZ7KBAL06sf/AQK/0oqcCQLnrI+ZD94ytl4m3yVK2AjSmUM/lJpk24m3".'&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2';
}
//$POSTFIELDS = '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=vwx7a&password=smwhe&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2';
//$ch = curl_init();
$ch = $this->ch;
curl_setopt($ch, CURLOPT_URL,$loginurl);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
return $result;
curl_close ($ch);

}
?>

0
<?php
$url="http://nbk2.autodata.no/default.aspx?11=4&14=12&10=0091771271436042004012&12=1003";
 $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
        curl_setopt($ch, CURLOPT_TIMEOUT, 20); // times out after 4s
        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
curl_setopt($ch, CURLOPT_COOKIEJAR, './cook.txt'); 
curl_setopt($ch, CURLOPT_COOKIEFILE, './cook.txt'); 
		$html = curl_exec($ch);
echo $html;

$ch = curl_init('http://nbk2.autodata.no/default.aspx?11=4&14=12&10=0091771271436042004012&12=1003&204=false');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=admin&password=passw&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
	

    curl_setopt($ch, CURLOPT_COOKIEJAR, './cook.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, './cook.txt');
    $res = curl_exec($ch);
	echo $res;
?>
0

Did you check this code with the provided username and password.? it doesn't work here now.I checked it with this username and password. user: vwx7a
Pass : smwhe
I think the dynamically generated url makes the issue in login section...

0
<?php
$url="http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18";
 $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
        curl_setopt($ch, CURLOPT_TIMEOUT, 20); // times out after 4s
        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
curl_setopt($ch, CURLOPT_COOKIEJAR, './cook.txt'); 
curl_setopt($ch, CURLOPT_COOKIEFILE, './cook.txt'); 
		$html = curl_exec($ch);


$ch = curl_init('http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '__VIEWSTATE=%2FwEPDwULLTE2OTYxMTQyOTJkZKnDWEWkr2o2KzEZL%2FUtwkVYytbh&__EVENTVALIDATION=%2FwEWBAKCiZ7KBAL06sf%2FAQK%2F0oqcCQLnrI%2BZD94ytl4m3yVK2AjSmUM%2FlJpk24m3&ctl00%24tbUserName=vwx7a&ctl00%24tbPassword=smwhe&ctl00%24btnLogin=');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
	

    curl_setopt($ch, CURLOPT_COOKIEJAR, './cook.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, './cook.txt');
    $res = curl_exec($ch);
	echo $res;
?>
0

Hi,

i am facing an issue in the curl search method, i implemented the curl login with your help but in the case of search page
i tried to implement the same method but it does not return the search result page .Here I am placing the home url and the search
credentials but it doesn't work please help
this is my code:

ob_start();

    echo $searchRes =  curlLogin(); 

function curlLogin(){

$baseurl = "http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18";
        $loginurl = "http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18";
//      $userName = "vwx7a";                //value of username
//      $userPwd = "smwhe";                             //value of password field       
//      $loginButton = "";                                      //value of login button
//      $userfieldname = "ctl00$tbUserName";                                //name of the field username
//      $passfieldname = "ctl00$tbPassword";                                //name of the field password
//      $buttonName = "ctl00$btnLogin";                                         //name of the submit button
        //$spiderId = $LoginDetails['idSpiders'];                                           //end values
        $link = "VW";                                                           
        $cookie_file_path = "/cook.txt"; 
        $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
        $reffer = "http://www.norskbildelkatalog.no/default.aspx?cat=2&Id=18";
            //  if($passfieldname!="") {                                 //for sites that have a password field
                        $password = '&' .$passfieldname.'=';
                    $POSTFIELDS = 'tp_articlesearch_pnl_search_vehicle_criterion=1&tp_articlesearch%24input_search_single=AA52844&tp_articlesearch%24btn_search_single=tp_articlesearch_btn_search_single&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=vwx7a&password=smwhe&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2';
                //}
                //$POSTFIELDS = '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJOTEyNTM2NDY2ZGReJw3PG62XkgM7gYqdrdP%2B0zHxDQ%3D%3D&username=vwx7a&password=smwhe&login=Send&__PREVIOUSPAGE=oL0kSGhtXbLqdHQg0uFgqg2'; 
                    $ch = curl_init(); 
                    curl_setopt($ch, CURLOPT_URL,$loginurl);
                    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
                    curl_setopt($ch, CURLOPT_POST, 1); 
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                    curl_setopt($ch, CURLOPT_REFERER, $reffer);
                    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
                    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

                    $result = curl_exec ($ch);

                    return $result;
                    curl_close ($ch); 

        }

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.