cURL / Mailing Lists / curl-users / Single Mail

curl-users

login POST with php/libcurl

From: Joe Glass <glassjos_at_msu.edu>
Date: 06 May 2003 16:13:46 -0400

I'm having trouble with initiating a login using curl (I've tried on the
command line and with PHP.)

With a browser, if I go to http://members.apa.org, then click on "Member
Directory", I am sent to a login page with the url
http://www5.apa.org/membership/login/login.cfm?CFID=1819003&CFTOKEN=60173325. So it appears a cookie is established. I can then enter in the username and password and click login, and everything is dandy.

I'm trying to automate this using PHP/libcurl. First, if I try to
access this site on the command line using:
curl -u username:passwd "http://www5.apa.org/membership/login/login.cfm"
It doesn't work, the same login page is simply returned. This is the
same behavior I get when using php, no matter what I try. See below to
check out my code. The only thing that clues me to as what I am doing
right or wrong is, when I enter the wrong username/password combination
I am sent to an incorrect password page. But when I put in the correct
user name I stay at the login page. Any suggestions?

Thank you,
Joe Glass

<?php

$id = "username";
$pw = "password";
$postfields = "UserLogin=$id&UserPassword=$pw&press=login";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1); // Get the header
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_COOKIEJAR, "/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);
?>

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