Alex Rivera | Logout

Gravatar: How do I know if a user has a real picture

Asked 2010-01-20T17:50:22.573
41

I have gotten the gravatar service working on my site. But I would like to know if the user has uploaded their picture or not. Is there a way to know this?

Edit
Report

1 Answer

0
function get_gravatar( $email, $s = 80, $d = '404', $r = 'x', $img = false, $atts = array() ) {

$url = 'http://www.gravatar.com/avatar/';
$url .= md5(strtolower(trim($email)));
$url .= "?s=$s&d=$d&r=$r";

if ( $img ) 
{
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
return $url;

}

$headers = @get_headers($url);

if (!preg_match("|200|", $headers[0])) 
{
$has_valid_avatar = 'no';
} 
else 
{
$has_valid_avatar = 'yes';
}

return $has_valid_avatar;

}
answered 2012-05-19T07:13:51.630

Your Answer