How to validate a LinkedIn public profile url

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.


I've found a number of ways the profile url can look like:

http://uk.linkedin.com/pub/some-name/1/1b3/b45/
http://nl.linkedin.com/pub/other-name/11/223/544
http://www.linkedin.com/in/aname/
http://www.linkedin.com/in/another-name
http://linkedin.com/in/name
http://nl.linkedin.com/in/name
http://nl.linkedin.com/in/name/

I've used this regex to describe it:

^https?://((www|\w\w)\.)?linkedin.com/((in/[^/]+/?)|(pub/[^/]+/((\w|\d)+/?){3}))$

It is not strict-strict but it got me home.

edit
- Added https support

Tags:

Php

Linkedin