Page 1 of 1

Autologin on a asp based website

Posted: Tue Aug 16, 2011 8:16 am
by LuaMadman
Hi

I'm trying to do a autologin to our companys supplyer.
I know that the form is on order.se/top.asp

On google i found the following script that i moddiefied for my need, but i still don't get logged in.

I used the Live HTTP Headers to get that post string I should send is the following:
action=login&guid=0&CustomerNo=****&UserPassword=****&UserName=****
Then i return to the top.asp page. beacuse when logged in, the content looks diffrent.

Code: Select all

<?php
// David Steele
// inventory_updater.php -- Goes out to each of the three websites, logs in, and gets the information
// Note: Some of the code in this program is borrowed from bpat1434 on the page http://www.phpbuilder.com/board/showthread.php?t=10346748 -- Thanks bpat

$cookiePath = "cookies.txt";

function login($loginURL, $username, $userFieldName, $password, $passFieldName, $extraContent, $custno, $custnoFieldName)	{
	// Initialize the page
	$page = curl_init($loginURL);
	// Set POST data
	curl_setopt($page, CURLOPT_POST, 1);
	$postData = $extraContent . $custnoFieldName . '=' . $custno . '&' . $passFieldName . '=' . $password . '&' . $userFieldName . '=' . $username;
// 	$postData = $userFieldName . '=' . $username . '&' . $passFieldName . '=' . $password;
// 	if(!empty($extraContent))	$postData = $postData . '&' . $extraContent;
	curl_setopt($page, CURLOPT_POSTFIELDS, $postData);

	// Set cURL not to print page
	curl_setopt($page,	CURLOPT_RETURNTRANSFER,	true);

	// Set the location to store the cookies
	curl_setopt($page, CURLOPT_COOKIEJAR, $cookiePath);
	curl_setopt($page, CURLOPT_COOKIEFILE, $cookiePath);

	// return the cURL variable for later use
	return $page;
}
$url = 'http://www.order.se/top.asp';
$username = '****';
$password = '****';
$custno = '****';
$userFieldName = 'UserName';
$passFieldName = 'UserPassword';
$custnoFieldName = 'CustomerNo';
$extraContent = '/logindo.asp action=login&guid=0&';

// $page = login($url);
$page = login($url, $username, $userFieldName , $password, $passFieldName,$extraContent, $custno, $custnoFieldName);

// Go to the page and log in
curl_exec($page);

// Change the URL to the main page to check to see if the user is logged in
// curl_setopt($page, CURLOPT_URL, "http://www.order.se/pricelist.asp");
curl_setopt($page, CURLOPT_URL, "http://www.order.se/top.asp");

// Print the output
print curl_exec($page);
?>

Re: Autologin on a asp based website

Posted: Tue Aug 16, 2011 9:24 am
by phphelpme
From what I can see to start off with is you have a space in this line:

Code: Select all

$extraContent = '/logindo.asp action=login&guid=0&';
Which should be:

Code: Select all

$extraContent = '/logindo.asp?action=login&guid=0&';
Notice the question mark!

Just as a hunch wouldn't you still need to follow the location even though it goes back to the same page with your return $page; ?

Code: Select all

curl_setopt ($page, CURLOPT_FOLLOWLOCATION, 1);
But I suppose you would be loading the first page twice at the end then maybe. :)

Best wishes

Re: Autologin on a asp based website

Posted: Wed Aug 17, 2011 1:48 am
by LuaMadman
I made the changes you suggested, but it didn't help.

Re: Autologin on a asp based website

Posted: Thu Aug 18, 2011 1:11 am
by LuaMadman
I tried changeing the url to logindo.asp instead of top.asp, but still no go.

Re: Autologin on a asp based website

Posted: Thu Aug 18, 2011 5:41 am
by phphelpme
Should this line:

Code: Select all

$extraContent = '/logindo.asp action=login&guid=0&';
Be this instead:

Code: Select all

$extraContent = 'action=login&guid=0&';
But you could try this code as I cant try it because I dont have an account to login with

Code: Select all

$url = 'http://www.order.se/top.asp';
$username = '****';
$password = '****';
$custno = '****';
$userFieldName = 'UserName';
$passFieldName = 'UserPassword';
$custnoFieldName = 'CustomerNo';
$extraContent = 'action=login&guid=0&';
$postData = $extraContent . $custnoFieldName . '=' . $custno . '&' . $passFieldName . '=' . $password . '&' . $userFieldName . '=' . $username;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$store = curl_exec($ch);

echo $store;
Check to see if you login with the above script as it will echo the results on the page from $store variable.

Just a question though, what is $loginURL for in your script because you set variable $url but not $loginURL?

Best wishes

Re: Autologin on a asp based website

Posted: Thu Aug 18, 2011 7:44 am
by LuaMadman
$loginURL is $url. $url is sent to function as $url but inside the function it's called $loginURL

And your code worked fine, just had to change the $url to http://www.order.se/logindo.asp

Thank you very much!

Re: Autologin on a asp based website

Posted: Thu Aug 18, 2011 8:35 am
by phphelpme
Glad I could help you out buddy.

Best wishes