Link to home
Start Free TrialLog in
Avatar of WhistlingMtn
WhistlingMtn

asked on

PHP Curl into ASPX website

Hey, I have sister websites, one of them is with a CM system in aspx ( do not have access to source code ). I'm trying to login and scrape from a list, but just.. nothing happens, no error.. any help would be wonderful. I've tested the script on non-aspx logins and it works fine, I've tried it using the EVENTSTATE and EVENTVALIDATION variables there or not.
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
	session_write_close();

	$agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

	// Login

	$back = 'txtUsername=[username]&txtPassword=[password]&chkRememberMe=on&btnSubmit=Login';
	$back .= "&__EVENTVALIDATION=/wEWBQLTg7DMBQKl1bK4CQK1qbSRCwLC8qqaCgLCi9reA/HCC7Z/TFEFxbmdxzpyokLktjos";
	$back.= "&__EVENTSTATE/wEPDwULLTEyMTcwMTQ3MDFkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQ1jaGtSZW1lbWJlck1l+uyKxry09hPIkqVla98roCW+U9k=";
	$back_url = "[login url];
	
	$url=$back_url;
	$vars=$back;

	 $options = array(
		CURLOPT_REFERER => $back_url,
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
		CURLOPT_POST		   =>1,
		CURLOPT_POSTFIELDS		=> $vars ,
		CURLOPT_COOKIEJAR	=> 'cookie.txt',
		CURLOPT_COOKIEFILE => 'cookie.txt',
		CURLOPT_SSL_VERIFYHOST => 0,
		CURLOPT_SSL_VERIFYPEER => 0,
		CURLOPT_USERAGENT => $agent,
		CURLOPT_COOKIE => $strCookie 
    );

    $ch      = curl_init( $url );

    curl_setopt_array( $ch, $options );

    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

Open in new window

Avatar of p_nuts
p_nuts
Flag of Netherlands image

have a go at it with snoopy..
http://sourceforge.net/projects/snoopy/
that does all the curl stuff for you.. much easier to use a class that works instead of having to re-invent the wheel.
P_nuts
Avatar of WhistlingMtn
WhistlingMtn

ASKER

I've never heard of it. I'll try it out later today.
Snoopy really doesn't have the greatest documentation, I can't seem to get it to work even with the logins I have working with libcurl. There doesn't seem to be an option to set the cookie file, do you know of an example somewhere of a snoopy login?
ASKER CERTIFIED SOLUTION
Avatar of p_nuts
p_nuts
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yea, I can't get it to work, I think I'll stick with the libcurl, at least I know I have that working on other logins.
Ok, one step further, using the livehttpheaders plugin for Firefox I was able to direct grab the post vars from logging on, they must have had to be in a specific order. The cookie is created after login, but it doesn't seem to retain the session.. so onto that.
Hmm, I think it's not working because one of the set-cookie is "Secure"
Ok, I have a tentative success. I pulled the set-cookie line from the headers returned and appended it to the cookie file, and the first couple tests, successful!