The easy way is to check with invalid user/password. The other way is to actually check the headers, this may be useful when you just want to get something out of the headers.
After looking at the curl error codes I didn't see any 407 reference, and the curl authors don't really care about making the lib useful and easy to use at the same time
(
http://curl.haxx.se/mail/lib-2006-09/0272.html ) , here's how to actually check the headers for the error.
php curl_setopt ->> CURLOPT_HEADERFUNCTION
quote from the manual:
The name of a callback function where the callback function takes two parameters. The first is the cURL resource, the second is a string with the header data to be written. The header data must be written when using this callback function. Return the number of bytes written.
I know it says 'written' and not 'read', but this function actually checks the headers receiver from the server.
The headerfunction allows you to check for some text in the headers, but unfortunately the only way (I know) to get data out of it is to use a global var. I've been using something like this to get the cookies out of the header into an array. So here is what it should look like:
function headerfunc($ch,$data)
{
global $somevar;
//replace function with stristr 407 or preg_match or something
if(something_looks_wrong_in_headers($data))
{
$somevar=TRUE;
}
return strlen($data);
}
Initialize $somevar with FALSE just before doing curl_exec and check its value afterwards.
$ch=curl_init();
.....
.....
curl_setopt($ch,CURLOPT_HEADERFUNCTION,'headerfunc');
$somevar=FALSE;
$response=curl_exec($ch);
if($somevar)
{
do_something();
}