I was looking for help with a problem I have using cURL to get info from a site.
I’m a newbie using cURL, so I need some guidance with this. I need to login to 3dstats.com automatically and then recover a list of data. With the list there’s no problem, I’m already working on a solution; it’s the login that I can’t get to work. The login form, after much cleaning up, is something like this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
<title></title>
</head>
<body>
<form action="/cgi-bin/edit2.cgi" method="post">
<input type="hidden" name="type" value="2" />
<input type="text" class="flinput" size="40" name="usr" value="00000000" />
<input type="password" size="40" name="UsrPass" class="flinput" />
<input type="submit" value="Submit " class="binput" />
</form>
</body>
</html>
So, I need to send 3 variables, type, usr, and UsrPass. If I save this page and click Submit, the form works fine (after changing the fields to hidden and populating them with the correct login values, of course).
However, if I do this:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://3dstats.com/cgi-bin/edit2.cgi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array("type" => "44",
"usr" => "correct8-digitNumber",
"UsrPass" => "correctPassword");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/3dstats/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/3dstats/cookies.txt');
$output = curl_exec($ch);
$info = curl_getinfo($ch);
echo "<pre>";
print_r($info);
echo "</pre>";
echo $output;
curl_close($ch);
?>
the form returns: “Error : Wrong Account”, with the account number already populated to ” 0000″ (note the space). The account is an 8-digit number.
Any ideas as to what I’m doing wrong? The page says it is using cookies. What is the correct form of capturing/using them later? What I’m trying doesn’t seem to be working.
Thanks in advance for any help/advice.
To answer my own question and for future reference, the way it worked was like this:
The login now works.