NYCPHP Meetup

NYPHP.org

Using cURL to login to a page

Ophir Prusak ophir at prusak.com
Mon May 5 10:04:04 EDT 2003


I'm trying to write a script that will login to a username password
restricted page so I can grep the page for some info.

I'm trying to do this with cURL, but for some reason, I always get
redirected back to the login page (with an error=1 in the URL).

The site is using cold fusion.

The login page is http://www.audienceextras.com/extrasapp/login/login.cfm
though if you go to their homepage at http://www.audienceextras.com/ and
click on member login, you get extra data in the URL as such
http://www.audienceextras.com/extrasapp/login/login.cfm?CFID=423367&CFTOKEN=5daa9ea-b5ba6910-7e3a-11d7-85fd-00508bc99e4f

Here's the code I'm currently using:

<?
$ch = curl_init();

curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/curl_cookies");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/curl_cookies");

curl_setopt($ch,
CURLOPT_URL,"http://www.audienceextras.com/extrasapp/login/loginchk.cfm?requ
esttimeout=120");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "memid=<my member id>&pin=<my
password>");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01;
Windows NT 5.0)");

curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);

$data = curl_exec($ch);
curl_close ($ch);

print "Data is<br>\
";
print $data

?>

and here's the header I'm getting back:
HTTP/1.1 100 Continue Server: Microsoft-IIS/4.0 Date: Mon, 05 May 2003
13:45:23 GMT HTTP/1.1 302 Object Moved Location:
login.cfm?error=1&CFID=423385&CFTOKEN=5619600-b5ba6922-7e3a-11d7-85fd-00508b
c99e4f Server: Microsoft-IIS/4.0 Content-Type: text/html Content-Length: 198
HTTP/1.1 200 OK Server: Microsoft-IIS/4.0 Date: Mon, 05 May 2003 13:45:24
GMT Connection: close Content-type: text/html Page-Completion-Status: Normal
Page-Completion-Status: Normal Set-Cookie: CFID=; expires=Sat, 05-Apr-2003
08:45:24 GMT; path=/; Set-Cookie: CFTOKEN=; expires=Sat, 05-Apr-2003
08:45:24 GMT; path=/;

Any suggestions ??

thanx
ophir





More information about the talk mailing list