Get Google Profile Picture URL by email id using PHP

PHP

This is a trick using Google Profile.
First of all we are going to set a variable with a Google E-mail address (Gmail address). We are going to set it with my E-mail address

$email=’subins2000@gmail.com’; 

Then we are going to split @ from the mail address.

list($id, $domain) = split(“@”,$email);

Next we are going to send a request to Google Profiles to fetch the IMAGE url.

$headers = get_headers(“https://profiles.google.com/s2/photos/profile/”.$id, 1);

The variable $id above is from the splitted part.
Finally we have to get the URL of the user’s profile picture.

$url = $headers[‘Location’];

We have now got the Image URL. The overall code will be :

$email=$_GET[‘gmail’];
list($id, $domain) = split(“@”,$email);
$headers = get_headers(“https://profiles.google.com/s2/photos/profile/”.$id, 1);
$url = $headers[‘Location’];

You could do whatever with the IMAGE URL.