Jump to content

cURL automatic login


jkkenzie

Recommended Posts

Am trying to auto login at http://track.aasoftwares.net/pages/Premium_Tracking.htm

 

am trying the following cURL but i get no results:

<?php

//initiate curl process
$ch = curl_init();
$url = "http://track.futuresystems.co.ke/";

//set options
/*
There are a number of options, which you can use to manipulate
the behaviour of this ''invisible browser''.
See php.net/curl for more details.
*/

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'txtUserName3=******&txtPassword3=*****');

//run the process and fetch the document
$doc = curl_exec($ch);

//terminate curl process
curl_close($ch);

//print output
echo $doc;

?>

any help!

Link to comment
Share on other sites

Hi jkkenzie,

 

Looking at the source code, there appear to be some hidden input fields that are being sent. Primarily a "__VIEWSTATE", which I would assume is some sort of session/temporary key to try to prevent what you are trying to do.

 

However, never fear! There is a solution :)

 

Here is some revised code. I've tested it and instead of giving me a login box it gives me an internal server error. Try it with actual credentials and let us know what happens.

 

<?php

//initiate curl process
$ch = curl_init();
$url = "http://track.futuresystems.co.ke/";

//set options
/*
There are a number of options, which you can use to manipulate
the behaviour of this ''invisible browser''.
See php.net/curl for more details.
*/

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

//run the process and fetch the document
$doc = curl_exec($ch);


// extract viewstate input field
$viewstate = explode('<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="',$doc);
$viewstate = explode('" />',$viewstate[1]);
$viewstate = $viewstate[0];

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'txtUserName3=******&txtPassword3=*****&__VIEWSTATE='.$viewstate);

//run the process and fetch the document
$doc = curl_exec($ch);

//terminate curl process
curl_close($ch);

//print output
echo $doc;

?>
Link to comment
Share on other sites

  • 2 months later...

Hi monkeypaw201!

 

I have a similar issue, except I log into a secure site.  I've got this part working by using the following:

	$url = "https://www.fragrancex.com/customeraccount/customer_center.html";
	$cr = curl_init($url); 
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt");
	
	$curl_ret = curl_exec($cr); 
	curl_close($cr); 


	//run the process and fetch the document
	$doc = curl_exec($ch);

	//print output
	echo $doc;

however, now I need to pass a value $__RequestVerificationToken back to the page and submit to login.  I've borrowed your example above and tried a couple things, but it won't login.

 

Would you kindly assist?

 

Here's the full code:

 


<?php

	$url = "https://www.fragrancex.com/customeraccount/customer_center.html";
	$cr = curl_init($url); 
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt");
	
	$curl_ret = curl_exec($cr); 
	curl_close($cr); 


	//run the process and fetch the document
	$doc = curl_exec($ch);

	
	// extract __RequestVerificationToken input field
	$__RequestVerificationToken = explode('<input name="__RequestVerificationToken" type="hidden" value="',$doc);
	$__RequestVerificationToken = explode('" />',$__RequestVerificationToken[1]);
	$__RequestVerificationToken = $__RequestVerificationToken[0];
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt");

	// ENABLE HTTP POST
	curl_setopt ($ch, CURLOPT_POST, 1);
	
	// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
	curl_setopt ($ch, CURLOPT_POSTFIELDS, '__RequestVerificationToken='.$__RequestVerificationToken.'&UserName=somewhere%40over.the.rainbow&NewUser=False&Password=12345&action=Sign+in+using+our+secure+server&ReturnUrl=');
	
	//run the process and fetch the document
	$doc = curl_exec($ch);
	
	//terminate curl process
	curl_close($ch);

	//print output
	echo $doc;

?>

Thanks in advance!

 

J

Link to comment
Share on other sites

  • 4 months later...

hello Jimmie89

 

I have a similar issue for fragrancex login...

 

Found you the solution?

 

Thanks in advance!

Hi monkeypaw201!

 

I have a similar issue, except I log into a secure site.  I've got this part working by using the following:

	$url = "https://www.fragrancex.com/customeraccount/customer_center.html";
	$cr = curl_init($url); 
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt");
	
	$curl_ret = curl_exec($cr); 
	curl_close($cr); 


	//run the process and fetch the document
	$doc = curl_exec($ch);

	//print output
	echo $doc;

however, now I need to pass a value $__RequestVerificationToken back to the page and submit to login.  I've borrowed your example above and tried a couple things, but it won't login.

 

Would you kindly assist?

 

Here's the full code:

 


<?php

	$url = "https://www.fragrancex.com/customeraccount/customer_center.html";
	$cr = curl_init($url); 
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt");
	
	$curl_ret = curl_exec($cr); 
	curl_close($cr); 


	//run the process and fetch the document
	$doc = curl_exec($ch);

	
	// extract __RequestVerificationToken input field
	$__RequestVerificationToken = explode('<input name="__RequestVerificationToken" type="hidden" value="',$doc);
	$__RequestVerificationToken = explode('" />',$__RequestVerificationToken[1]);
	$__RequestVerificationToken = $__RequestVerificationToken[0];
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt");

	// ENABLE HTTP POST
	curl_setopt ($ch, CURLOPT_POST, 1);
	
	// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
	curl_setopt ($ch, CURLOPT_POSTFIELDS, '__RequestVerificationToken='.$__RequestVerificationToken.'&UserName=somewhere%40over.the.rainbow&NewUser=False&Password=12345&action=Sign+in+using+our+secure+server&ReturnUrl=');
	
	//run the process and fetch the document
	$doc = curl_exec($ch);
	
	//terminate curl process
	curl_close($ch);

	//print output
	echo $doc;

?>

Thanks in advance!

 

J

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.