How to validate a LinkedIn public profile url

maaudet picture maaudet · Dec 9, 2011 · Viewed 14.8k times · Source

I am looking for a way to validate a link to make sure that it is pointing to a LinkedIn public profile page in PHP.

I have a website and I would like my users to be able to share their LinkedIn profile in their profile on my website.

Answer

Alex picture Alex · Dec 9, 2011

Try something like this where $username is the linked-in username. You also can set $profileurl directly to the link given and verify with str_pos that is starts with http://www.linkedin.com/in/

$profileurl = "http://www.linkedin.com/in/".$username;

$fp = curl_init($profileurl);
$response = curl_exec($fp);
$response_code = curl_getinfo($fp, CURLINFO_HTTP_CODE);
$validprofile = ($response_code == 200);

$validprofile will be a boolean indicating if the profile is valid.