PHP Profile Data

← Back

We are personally used to working in PHP all the time, and part of that is serialize()ing data structures to store them as strings sometimes. Since that seems to be a common approach, we decided to provide an option to get Gravatar profile data as a serialized PHP string.

Base Request

Making a PHP request is likely to follow these steps (assuming you have an email address already):

  1. Create a valid email hash
  2. Build the URL to request a profile page
  3. Append .php to that URL to indicate that you want the results in serialized PHP format

Once you have done the above, you should end up with a URL that looks something like this:

https://www.gravatar.com/205e460b479e2e5b48aec07710c08d50.php

When you request that URL (you can do it in your browser) you should get a document containing a serialized string with all open profile data. We use Portable Contacts to format our profile data whereever possible, so see the PoCo spec for more details on the structure of the response.

Request Options

The PHP data format does not support any additional options

Example

This example (written in PHP, and assuming you can file_get_contents()) just loads up my profile in serialized PHP, then unserializes it and outputs my name:

	<?php

	$str = file_get_contents( 'https://www.gravatar.com/205e460b479e2e5b48aec07710c08d50.php' );
	$profile = unserialize( $str );
	if ( is_array( $profile ) && isset( $profile['entry'] ) )
		echo $profile['entry'][0]['displayName'];

	?>

Tips

  1. For security, we recommend always using HTTPS connection when making PHP requests.
  2. Note the structure of the response; an array containing one element ('entry'), which contains an array containing a single array. This is to match with the PoCo spec
  3. Links (a href) within the "Description" field are automatically modified to include rel="nofollow" on profile pages, but the raw profile data does not have this change applied.
  4. As with all profile data formats, profile requests will only resolve for the hash of the primary address on an account. Users may have multiple addresses on a single account, so while a Gravatar image request may return a result, a profile request for the same hash may not.