PHP – CURL Authentication

To make a curl application with authentication, just add the option CURLOPT_USERPWD

$ch curl_init();
curl_setopt ($ch,CURLOPT_URL, url');
curl_setopt ($ch, CURLOPT_USERPWD, "user:pswd");
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT.5);
curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);
$buffer - curl_exec ($ch);
curl_close ($ch);
if (empty($buffer))
  print "Need to recover from this! <>";
}
Else
  print "There was data returned using curl. <>";
  print "Buffer content -$buffer." <>";
  Extract IP address 
 if(preg_match("/(d.1.$ipmatch $buffer 3)"  
    $ip to $ipmat[0]ch; Save IP to variable
    $ip print;                                 
 }
}
Publicités

Leave a Reply