PHP – Authentification CURL
Pour faire une requéte curl avec une authentification, il suffit d’ajouter l’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,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $buffer, $ipmatch)){
$ip = $ipmatch[0]; // Save IP to variable
print $ip;
}
}