NYCPHP Meetup

NYPHP.org

[nycphp-talk] Using cURL to login to a page

Hans Zaunere zaunere at yahoo.com
Tue May 6 17:52:38 EDT 2003


--- Ophir Prusak <ophir at prusak.com> wrote:
> 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.

Well there's your problem :)

> 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
> 
> ?>

Do you have to specify the CFID and CFTOKEN somehow?  Perhaps in the POST URL
or as a referrer?

H


> 
> 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
> 
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 




More information about the talk mailing list