cURL / Mailing Lists / curl-and-php / Single Mail


Retrieving the authenticated username:password from server with PHP

From: Christopher Vrooman <>
Date: Tue, 18 Mar 2008 01:49:00 -0300

  I have found a ton of tutorials that show how to submit a
username:password; however, what I want to know is how to retrieve
those values in PHP on the server side.

  If I have a user and lookup their username/password, then I want to
validate them automatically, so I have tried the following:

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, ';
  curl_setopt($ch, CURLOPT_USERPWD, 'user:123456');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "Hello=World&Foo=Bar&Baz=Wombat");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_VERBOSE, true);

However, when I do a var_dump($GLOBALS), the username/password don't
appear anywhere.

I would assume they would show up in $_SERVER['PHP_AUTH_USER'] &
$_SERVER['PHP_AUTH_PW'], but those two variables have never, ever
appeared for me.

I have tried curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); and
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); in an attempt to
find something that will work, but have had no luck.

Can anyone offer some advice? I'm using PHP5.2.1 with libcurl/7.15.3
OpenSSL/0.9.7a zlib/1.2.3 libidn/0.5.6 on a shared server, so no real
chance to upgrade to a newer version (if that's the problem).

Thanks in advance,
     Christopher Vrooman.

P.D. I have a Jailed SSH, so if you need any info off of the server,
just let me know.
Received on 2008-03-18