O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — adding Gravatars to our application

Adding support for Gravatars through our user class is as easy as adding a few lines of code. After that, we'll add the gravatar function all over our application.

  1. Open user/profile.php and a public function called gravatar that accepts a parameter called size; we'll give it a default value of 50.
    public function gravatar($size='50') {
    }
    
  2. In order to get the users' Gravatar, we just need to create an md5 hash of a user's e-mail address, which will serve as the gravatar_id. We'll then set the size using our $size variable, and append all of that to Gravatar's web service URL.
    public function gravatar($size='50') { return 'http://www.gravatar.com/avatar/?gravatar_id=' .md5(strtolower($this->email)).'&size='.$size; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required