Hi guys!
I have made some little PHP code that check the owner of a photo on Facebook that the user inputs.
I'm not sure that it works, but I can't see it a reason why it shouldn't haha. I have no option to run it at the moment, so feel free to test it and fix it in case it doesn't work (will be mainly dumb mistakes ).
I commented everything, so I hope it helps someone who tries to study PHP. It's VERY basic, but cute.
Here is the HTML front page:
And here is the data.phpPHP Code:
<html>
<body>
<form action="data.php" method="post">
http://www.<input type="text" name="address">
<input type="submit">
</form>
</body>
</html>
PHP Code:
<html>
<body>
<?php
$address = $_POST["address"]; //getting the address
$start = strrpos($address,"."); //last dot in the address, the ID starts there
$start = $start++; //we don't need the dot, so we are moving forward
if(!strpos($address,"&type=1&theater")) //sometimes the user will put it too, so if he didn't do it (and the output will be FALSE), this will run
{
$id = substr($address,$start); //the substring starts where the $start is, and goes until the end
}
else //in case he didn't put the whole type and theater thing
{
$end = strpos($address,"&type=1&theater"); //this will be the end of the id
$id = substr($address,$start,$end - $start); //starts in $start and the length equals the position of the end minus the position of the start
}
$url = "http://www.facebook.com/profile.php?id=" . $id; //putting up the url
$str = file_get_contents($url); //getting the page source
$name_start = strpos($str,'<title id="pageTitle">'); //name starts here
$name_end = strpos($str,'</title>'); //name ends here
$name = substr($str,$name_start,$name_end-$name_start); //this will be the name
$name = str_replace('<title id="pageTitle">',"",$name); //we don't need the tag in the name, so we are deleting it
?>
The photo belongs to the user/page named <?php echo $name; ?>.<br>
The url to his profile is <?php echo $url; ?>
</body>
</html>
Results 1 to 5 of 5
- 28 Jul. 2013 04:35pm #1
Little PHP code to check photo owner on Facebook
- 28 Jul. 2013 07:27pm #2
A while back I actually rigged up a little web app to do just this.
You should expand on it a bit more.
Good work though. Just keep in mind it doesn't work for all URLs
Also, not proficient in PHP but wouldn't using a split function on the string be more reliable?I don't get tired.
- 29 Jul. 2013 05:42am #3
If you mean exploding it into an array, it's possible too.
JustPHP Code:explode(".",$address)
- 30 Jul. 2013 04:21pm #4
When did you make this? I know Facebook used to have a lot of complaints from people being able to harvest a user's profile page from their picture URLs and had fixed it. Dunno if this attempts to use the same system. But that was like a year ago or so.
- 30 Jul. 2013 05:55pm #5
I made it in the same day I posted it, so it should work.