Website parsing for specific data
Depending on what web application it is your making, sometimes it is necessary to verify ownership/verify that the person has access to a website they claim they own. For my other project, tibiaviplist, I verify that the user put a specific code in their characters comment before letting them register. This proves that they have access to the account. On one of my new site projects, I have the user place a code in their site to verify it is theirs before adding it to the directory.
Checking to ensure this code has been added is simple.
First, you need to download the entire html contents of the site:
$urlcontents = file_get_contents('http://bncapps.com');
Obviously replacing http://bncapps.com with the site you need to verify, or pass it a variable containing the site.
Then, we use a simple if statement to check to see if the code exists somewhere in the contents, for our example, lets make the code "--bncapps--".
$code = '--bncapps--'; if(strpos($urlcontents, $code)){ echo 'CODE FOUND!'; //do whatever since the code is found }else{ echo 'NOT FOUND'; //do whatever since it isnt found }
And that's it! If you have any other suggestions, let me know (the main language I am currently working with is PHP, so any suggestions will help me learn aswell!)




Reader Comments