K
K
Karen Mnatsakanyan2020-05-05 18:29:50
PHP
Karen Mnatsakanyan, 2020-05-05 18:29:50

Check by email if there is a gravatar?

Hello everyone, how can I check if there is an email engraver or not?

<?php 
      $email = $review['email'];
      $default = "https://www.somewhere.com/homestar.jpg";
      $size = 50;
      $grav_url = "https://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
    ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-05-05
@karjan

function isGravatar($email) {
  $uri = 'https://www.gravatar.com/avatar/' . md5($email) . '?d=404';
  $headers = get_headers($uri);
  return (bool) preg_match("|200|", $headers[0]);
}
// isGravatar('[email protected]');

K
Karen Mnatsakanyan, 2020-05-05
@karjan

Found solution on google

<?php
      $email = $review['email'];
      $hash = md5($email);
      $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
      $default = "https://www.somewhere.com/homestar.jpg";
      $size = 50;
      $headers = @get_headers($uri);
      if (!preg_match("|200|", $headers[0])){
        $grav_url = "catalog/view/theme/tbchoice/img/comment2.jpg";
      } else {
          $grav_url = "https://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
      } 
    ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question