PHP Profile Data
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.
Making a PHP request is likely to follow these steps (assuming you have an email address already):
- Create a valid email hash
- Build the URL to request a profile page
.phpto 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:
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.
The PHP data format does not support any additional options
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( 'http://www.gravatar.com/205e460b479e2e5b48aec07710c08d50.php' ); $profile = unserialize( $str ); if ( is_array( $profile ) && isset( $profile['entry'] ) ) echo $profile['entry']['displayName']; ?>
- 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
- 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.
- 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.