cURL / Mailing Lists / curl-users / Single Mail


login POST with php/libcurl

From: Joe Glass <>
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, then click on "Member
Directory", I am sent to a login page with the url 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 ""
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


$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,
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");


Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
Received on 2003-05-07