How to validate a LinkedIn public profile url

后端 未结 9 2925
迷失自我
迷失自我 2021-02-20 16:43

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 abl

相关标签:
9条回答
  • 2021-02-20 17:08

    Use a regex to ensure that the link matches the form taken by linkedin public profiles.

    0 讨论(0)
  • 2021-02-20 17:10

    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.

    0 讨论(0)
  • 2021-02-20 17:12

    I use another regular expression more permisive:

    ^(http(s)?:\/\/)?([\w]+\.)?linkedin\.com\/(pub|in|profile)

    It includes URLs without squeme and all samples from other answers. You can make any variation here http://regex101.com/r/vE8tV7

    0 讨论(0)
提交回复
热议问题