Hello super awesome people from stackoverflow!
I need help with this php script.. I want to get facebook id from user when it enters his facebook profile link in the input box. example of the profile link: https://www.facebook.com/profilename. I have a script that collect the "profilename"from the url and save it to the $username but now i need the script to convert that profilename to the facebook ID of that profile and save it to the $username. Now i know you can get facebook id manually easy when you right click on the user Profile Picture than click on Copy link adress and the last number after .(dot) is user profile ID..Or another method is to scan the page for <meta property="al:ios:url"
or <meta property="al:android:url"
That will also get user ID. And this is the site that has that working script. http://findmyfbid.com/
This is my code now: As you can see it only takes last part of the url.. Please help to make it right to convert that profilename to ID and save it to $username .Thank you.
/* CHECKING */
if (isset($_POST["urlCheck"])) {
$url = $_POST["urlCheck"];
$urlParts = explode("facebook.com/", $url);
$username = GetOnlyUsername($urlParts[1]);
if (filter_var($url, FILTER_VALIDATE_URL) !== false)
exit("success");
else
exit("error");
}
/* TAKING INFO */
if (isset($_POST["urlGetData"])) {
$url = $_POST["urlGetData"];
$urlParts = explode("facebook.com/", $url);
$username = GetOnlyUsername($urlParts[1]);
$name= GetData($username);
function GetOnlyUsername($username) {
if ((strpos($username, 'profile.php?id=')) !== false) {
$username = str_replace("profile.php?id=", "", $username);
if ((strpos($username, '&fref=ts')) !== false) {
$username = str_replace("&fref=ts", "", $username);
}
} else if ((strpos($username, '?')) !== false) {
$test = explode("?", $username);
$username = $test[0];
}
return $username;
}