cURL / Mailing Lists / curl-users / Single Mail

curl-users

SUMMARY: login POST with php/libcurl

From: Joe Glass <glassjos_at_msu.edu>
Date: Wed, 7 May 2003 22:04:01 -0400

Okay, I looked into it more and got my login to work. Below is the
code. I was missing was the CURLOPT_COOKIEFILE line. Actually, the
script doesn't work the first time because you have to set up the
connection to create a cookie in /tmp/cookie, but if you click reload
the cookie will be created and it will work.

I'm still having problems getting formfields.pl working with that page.
However I got it to work with the
http://www5.apa.org/membership/login/login.cfm page. I got it to work
with other pages, though.

Thank you for your help Daniel,
Joe Glass

$id = "username";
$pw = "password";
$postfields = "UserLogin=$id&UserPassword=$pw";
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie");
curl_setopt($ch, CURLOPT_URL,
"http://www5.apa.org/membership/login/login.cfm");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");

curl_exec($ch);
curl_close($ch);
unset($ch);

-----Original Message-----
From: curl-users-admin_at_lists.sourceforge.net
[mailto:curl-users-admin_at_lists.sourceforge.net] On Behalf Of Joe Glass
Sent: Wednesday, May 07, 2003 8:38 PM
To: curl-users_at_lists.sourceforge.net
Subject: RE: login POST with php/libcurl

Thanks again for your response Daniel. I am having trouble getting
formfind.pl v1.5 to work; my output is different from yours. All of my
inputs say "[weird]" and not the variable names. I tried "wget
http://www5.apa.org/membership/login/login.cfm" and then ./formfind.pl <
login.cfm. It looks like a very useful utility, though.

As for UserLogin/UserPassword values, how do I find out what they should
be? I tried leaving them null and with text but it doesn't work.

One more question. One example on the web site using the command line
curl it suggested to use press=OK. But in this situation you said I
didn't need a press=Login. Is that because CURLOPT_POST is set to 1
which means it will submit the form without "press" being set?

Thank you,
Joe Glass

-----Original Message-----
From: curl-users-admin_at_lists.sourceforge.net
[mailto:curl-users-admin_at_lists.sourceforge.net] On Behalf Of Daniel
Stenberg
Sent: Wednesday, May 07, 2003 12:55 PM
To: Curl Mailinglist
Subject: RE: login POST with php/libcurl

On Wed, 7 May 2003, Joseph Glass wrote:

> $id = "username";
> $pw = "password";
> $postfields = "UserLogin=$id&UserPassword=$pw&press=login";

You seem to be guessing here. Have to analyzed the <form> tag closely?

Formfind reports this on the form:

--- FORM report. Uses POST to URL "/membership/login/login.cfm"
Input: UserLogin_required (HIDDEN)
Input: UserPassword_required (HIDDEN)
Input: UserLogin (TEXT)
Input: UserPassword (PASSWORD)
Button: "Login" (SUBMIT)
--- end of FORM

So you should use a string similar to this:

 
"UserLogin_required=&UserPassword_required=&UserLogin=$id&UserPassword=$
pw"

... and you should take care to have the name and password URL-encoded.

At least, there should be no 'login' button, but the two <input> tags
without
value you need to check how they actually work.

-- 
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
Received on 2003-05-08