Curl, aspx, and pinnaclesports problem

Hello -
I have posted something akin to this problem before, but the tread is now locked so I’m starting a new one in the hope that someone can help me.

Here is my code to begin with:


<?php 
session_start();
$ch=login();
$html=downloadUrl('https://www1.pinnaclesports.com/members/betpage.asp', $ch);
echo $html;

function downloadUrl($Url, $ch){
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_REFERER, "http://www.google.co.uk/");
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = curl_exec($ch);
    return $output;
}

function login(){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.pinnaclesports.com/'); //login URL
    curl_setopt ($ch, CURLOPT_POST, 1);
    $postData='__EVENTTARGET=ctl00%24LF%24LB&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwULLTE1MTczNzI3NjUPZBYCZg9kFgQCAQ9kFgQCBA8WAh4EVGV4dAVUDQo8bWV0YSBuYW1lPSJ2ZXJpZnktdjEiIGNvbnRlbnQ9InJvT3JjOUljZHlZVFgrVDZnWm1PN2VQejMwRWNLR2VXTkJqbmwzWnlaQUk9IiAvPg0KZAIJD2QWAmYPFgIfAAWPATxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI%2BKi5pIHtiYWNrZ3JvdW5kLWltYWdlOnVybChodHRwczovL2Nkbi5waW5uYWNsZXNwb3J0cy5jb20vUmVzb3VyY2VzL3VwbG9hZGVkaW1hZ2VzL0d1ZXN0U2VjdGlvbi9jb21iaW5lZDI0LnBuZyk7fTwvc3R5bGU%2BZAIDDxYEHgZvbmxvYWQFMmphdmFzY3JpcHQ6UDdfaW5pdFBNKDEsOCwwLC0yMCwyKTtQN19pbml0VFAoNCwgMCk7HghvbnVubG9hZA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dD4NCjxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0IiBzcmM9Imh0dHBzOi8vdHJhY2tlci5waW5uYWNsZXNwb3J0cy5jb20vZS9jbGlja3MuanMiPjwvc2NyaXB0Pg0KPG5vc2NyaXB0Pg0KPGRpdiBzdHlsZT0iZGlzcGxheTpub25lIj48aW1nIHNyYz0naHR0cHM6Ly90cmFja2VyLnBpbm5hY2xlc3BvcnRzLmNvbS9lL3QzLmRsbD84MjUmYW1wOzAmYW1wOyUyMCZhbXA7TGFuZ3VhZ2VJRCUzRDIlMjZvZGRzRm9ybWF0JTNEZGVjaW1hbCZhbXA7aVJFR1FyeSZhbXA7aVNhbGUmYW1wOzAmYW1wOzAmYW1wOzAmYW1wOzAmYW1wOzAmYW1wOzAmYW1wOyUyMCZhbXA7MTUwMCZhbXA7JTIwJmFtcDswJyBoZWlnaHQ9IjEiIHdpZHRoPSIxIiBhbHQ9IkludGVsbGlUcmFja2VyIi8%2BPC9kaXY%2BDQo8L25vc2NyaXB0PjwhLS0vLy0tPg0KPCEtLSBFbmQgb2YgSW50ZWxsaVRyYWNrZXIgUGFnZSBUYWcgLS0%2BDQpkZA%3D%3D&__PREVIOUSPAGE=ZjCZnhAXRGZrXLMXv2ElUbt8p1W7iuq6Z4ovVzZVp-c1&ctl00%24LDDL=2&ctl00%24PSDDL=decimal&ctl00%24MCPH%24LF%24UserName=USERNAME&ctl00%24MCPH%24LF%24Password=PASSWORD&ctl00%24MCPH%24LF%24LanguageID=2&ctl00%24MCPH%24LF%24PriceStyle=decimal&ctl00%24MCPH%24LF%24LinesTypeView=c&ctl00%24MCPH%24LF%24MemberServer=www1.pinnaclesports.com&dvc=d'; 
	
	//echo $postData;
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookies.txt");
	curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookies.txt");

    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $store = curl_exec ($ch);
    return $ch;
}
?>

There is a cookie being written so I know it’s doing something, but the page doesn’t redirect - I just get greeted with a white screen.

Any thoughts folks?

DS

Can someone help me with a problem I’m having with Pinnacle also?

I’m using a Mac and trying to access Pinnaclesports.com but it just gives me a white screen and eventually times out. It started happening when I logged in using my name/password and clicked “save my username/password” on Firefox by mistake. Ever since then I can’t even see the site on my computer. I can access it fine from my cellphone.

I cleared the cookies but it still doesn’t work. Tried accessing it using Chrome. Tried restarting the computer. What should I do next??

I dont get any errors out, but without your password I cant run the script myself to check… what exactly are you trying to do with this?

Hey thanks for the reply.

I don’t get any errors either, but I’m not able to land on https://www1.pinnaclesports.com/members/betpage.asp either.

Simply - I want to arrive at this page: https://www1.pinnaclesports.com/members/betpage.asp as a logged in user and parse the resulting html.

I have written a script that will parse the html which I can get from manually logging in and saving the page.

Ideally then I would like to navigate to the english league fixtures and save those files too.

That __(VIEWSTATE|EVENTARGUMENT|EVENTSTATE) data you’re using, it nearly always changes on each request. You’re going to have to capture and use those in subsequent requests.

Being a US resident i cant register an account on that site, and therefore giving me links to it wont actually help anything unfortunately… one of the other guru’s can pop in and take a look at that part.

As far as you getting blank, try echo’ing [FPHP]curl_error[/FPHP] after each curl_exec and see if it spits anything out for you.

Hi - thanks for the suggestion.

Can you indicate how I would capture the viewstate on the fly each time?
I was under the impression that I would get the form field names and corresponding values from tamperdata or such and just force them.

Thanks.

DS

Good idea!
Thanks. I’ll post any findings.

I wonder… would making a transition from http:// on the login screen to https:// on the logged in side be a problem?

DS

edit

ok I’ve got this error…

Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:func(144):reason(134)


edit again

A quick google hunt leads me to this info…
I put this line in before $output = curl_exec($ch)

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

Now the script appears to run but I get this message:
Object Moved
This object may be found here. (the word here links back to the homepage - and not logged in)

Is this progress!?
Thanks guys.

It is progress. It does however mean, as Anthony indicated, that your login URL doesnt actually log you in. You’ll need to look at passing the post values into the actual form-handler for the login page.

Maybe something along these lines…


<?php
error_reporting(-1);
ini_set('display_errors', true);

function request($url, array $post = null, $cookie = 'cookie.file'){
  
  $handle = curl_init($url);
  
  if(false === file_exists($cookie)){
    touch($cookie);
  }
  
  $options = array(
    CURLOPT_RETURNTRANSFER  => true,
    CURLOPT_TIMEOUT         => 4,
    CURLOPT_COOKIEFILE      => $cookie,
    CURLOPT_COOKIEJAR       => $cookie
  );
  
  if(is_array($post)){
    $options[CURLOPT_POST] = true;
    $options[CURLOPT_POSTFIELDS] = http_build_query($post);
  }
  
  curl_setopt_array($handle, $options);
  
  return curl_exec($handle);
}

function get_input_value($name, $data){
  
  $pattern = sprintf(
    '~<input.*name="%s".*value="([^"]+)"~',
    preg_quote($name)
  );
  
  preg_match($pattern, $data, $matches);
  
  return empty($matches[1]) ? false : $matches[1] ;
}


/*
  Init session
*/
$visit = request('http://example.org/');

/*
  Perform login
*/
$login = request('http://www.example.org/login', array(
  '__VIEWSTATE'       => get_input_value('__VIEWSTATE', $visit),
  '__EVENTTARGET'     => get_input_value('__EVENTTARGET', $visit),
  '__EVENTARGUMENT'   => get_input_value('__EVENTARGUMENT', $visit),
  '__EVENTVALIDATION' => get_input_value('__EVENTVALIDATION', $visit)
));

/*
  Request auth'd page
*/
$account = request('http://example.org/');

Thanks for this.
I’m trying to piece together everything I need. I’m right in saying that I need all the form fields in here that are relevant to my login page?

Also - I fear that I’m submitting my information to something other than a login form. Let me rephrase - the login form is not the pinnacle sports home page so I’m not giving myself a chance here!

View the source of the login page and see what’s listed as the action attribute on the form tag.

Thanks… found this in the source

<form method="post" action="default.aspx" id="form1">

So this is the only form on the page so I’m going to work with this.
I’ll try to take all the ideas on this thread and put something together. I’ll probably need to post again, but thanks so much for the help so far. That goes for everyone here who has chipped in!

Ah crikey!

I’m not able to do this…
Here’s where I am. Tried to implement AnthonySterling’s suggestions.

I fear I may have bitten off more than I can chew.
I’m back to getting a blank screen. I tried adding some more error checking, but I didn’t get any feedback from the script on that.

I’m probably just rehashing the same problems in a different way, but is there anyone with more expertise than me be able to suggest a fix?



<?php
//error_reporting(-1);
ini_set('display_errors', true);

function request($url, array $post = null, $cookie = 'cookies.txt'){
  
  $handle = curl_init($visit);
  
  if(false === file_exists($cookie)){
    touch($cookie);
  }
  
  $options = array(
    CURLOPT_RETURNTRANSFER  => true,
    CURLOPT_TIMEOUT         => 4,
    CURLOPT_COOKIEFILE      => $cookie,
    CURLOPT_COOKIEJAR       => $cookie,
	CURLOPT_SSL_VERIFYPEER 	=> false,
    CURLOPT_FOLLOWLOCATION 	=> false
  );
  
  if(is_array($post)){
    $options[CURLOPT_POST] = true;
    $options[CURLOPT_POSTFIELDS] = http_build_query($post);
  }
  
  curl_setopt_array($handle, $options);
  echo 'Curl error: ' . curl_error($handle).'<br/>';
  return curl_exec($handle);
}

function get_input_value($name, $data){
  
  $pattern = sprintf(
    '~<input.*name="%s".*value="([^"]+)"~',
    preg_quote($name)
  );
  
  preg_match($pattern, $data, $matches);
  
  return empty($matches[1]) ? false : $matches[1] ;
}


/*
  Init session
*/
$visit = request('http://www.pinnaclesports.com/');

/*
  Perform login
*/
$login = request('http://www.pinnaclesports.com/default.aspx', array(
  '__VIEWSTATE'       => get_input_value('__VIEWSTATE', $visit),
  '__EVENTTARGET'     => get_input_value('__EVENTTARGET', $visit),
  '__EVENTARGUMENT'   => get_input_value('__EVENTARGUMENT', $visit),
  '__EVENTVALIDATION' => get_input_value('__EVENTVALIDATION', $visit),
  '__PREVIOUSPAGE' => get_input_value('__PREVIOUSPAGE', $visit),
  'LDDL' => get_input_value('ctl00$LDDL', $visit),
  'PSDDL' => get_input_value('ctl00$PSDDL', $visit),
  //'UserName' => get_input_value('ctl00$MCPH$LF$UserName', $visit), // should this be my username 'UserName' => 'USERNAME'
  //'Password' => get_input_value('ctl00$MCPH$LF$Password', $visit), // should this be my password 'Password' => 'PASSOWRD'
  'UserName' => get_input_value('******', $visit), // should this be my username 'UserName' => 'USERNAME'
  'Password' => get_input_value('******', $visit), // should this be my password 'UserName' => 'USERNAME'
  'LanguageID' => get_input_value('ctl00$MCPH$LF$LanguageID', $visit),
  'PriceStyle' => get_input_value('ctl00$MCPH$LF$PriceStyle', $visit),
  'LinesTypeView' => get_input_value('ctl00$MCPH$LF$LinesTypeView	', $visit),
  'MemberServer' => get_input_value('ctl00$MCPH$LF$MemberServer', $visit),
  'dvc' => get_input_value('dvc', $visit)

));

/*
  Request auth'd page
*/

$account = request('https://www1.pinnaclesports.com/members/betpage.asp');

?>



Here are the fields on the default.aspx form if that helps. The memberServer field value changes every time along with the viewstate

Hello again -

Drawn a complete blank.
I think this is beyond me. I just don’t know enough!

If anyone thinks they can complete this task there’s a few cups of coffee in it for them. Because it’s a recreational project I don’t have a budget to pay anyone properly to do it.

Frustration.

Thanks to the guys who had a go at helping me.

DS

‘UserName’ => get_input_value(‘‘, $visit),
‘Password’ => get_input_value(’
’, $visit),

well those should just be ‘UserName’ => “YourActualUsername” and ‘Password’ => “YourActualPassword”, for starters.

Second, check to see if a file called cookies.txt exists in your web directory where this page is executing; if it does not, you may need to create one so that the system can use it. (Funny thing about some systems’ permission settings.)

EDIT: sorry, they should read as ‘ctl00$MCPH$LF$UserName’ => “YourActualUsername” , etc. Name => Value.

  • Request Login Page (to initialise session)
  • Capture __* data then submit login data (following redirects)
  • Capture __* data then visit secure page
  • Capture secured page data.

Anthony - this bit about visiting secure page… I think I need this to be whatever is held in the MemberServer field of the form. From the code snippet you gave me before can you tell me some way to capture that?

e.g.

$account = request('MEMBER_SERVER_VALUE');

Thanks again guys.

DS

function request($url, array $post = null, $cookie = 'cookies.txt'){
  
  $handle = curl_init($visit);
  
  if(false === file_exists($cookie)){
    touch($cookie);
  }
  
  $options = array(
    CURLOPT_RETURNTRANSFER  => true,
    CURLOPT_TIMEOUT         => 4,
    CURLOPT_COOKIEFILE      => $cookies,
    CURLOPT_COOKIEJAR       => $cookies,
	CURLOPT_SSL_VERIFYPEER 	=> false,
    CURLOPT_FOLLOWLOCATION 	=> false
  );
  
  if(is_array($post)){
    $options[CURLOPT_POST] = true;
    $options[CURLOPT_POSTFIELDS] = http_build_query($post);
	echo $options[CURLOPT_POSTFIELDS]; //this is EMPTY! returns... __VIEWSTATE=0&__EVENTTARGET=0&__EVENTARGUMENT=0&__EVENTVALIDATION=0&__PREVIOUSPAGE=0&LDDL=0&PSDDL=0&UserName=0&Password=0&LanguageID=0&PriceStyle=0&LinesTypeView=0&MemberServer=0&dvc=0
  }
  
  curl_setopt_array($handle, $options);
  echo 'Curl error: ' . curl_error($handle).'<br/>';
  return curl_exec($handle);
}

I tried echoing some of the information to see if I could workout what is happening and there is nothing in the post info. Also the cookies file that is generating is blank. I checked it’s permission and writing to it is allowed on the server.

No end to my troubles! I think I’ll cry.

DS

Well, what you said it returns is not empty, it’s just not correct.

Does the form in question use single quotes, or double quotes around it’s values?