I have been working on the code and it currently looks like this:
<?php
function get_data($url) {
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
return $data;
}
$valid_username = array();
$handle = fopen("usernames.txt", "r");
if ($handle) {
while (($username = fgets($handle)) !== false) {
$url = "facebook.com/" . trim($username);
$source = get_data($url);
echo $url . "<br />";
if(preg_match_all('/<div class="coverBorder">/', $source, $matches)) { // If user exists, print its name. <div class="coverBorder"> confirms that the user exists since this class does not exist on Facebook's 404 page
echo "<font color='green'>" . $username . "</font>";
array_push($valid_username, $username);
}
else
echo "<font color='red'>" . $username . "</font><br />";
echo "<hr />";
}
fclose($handle);
} else {
echo "Error opening file";
}
?>
What I don't understand is that it's reporting false on some of the usernames even if though they do exist:
lisa and johanna should be green, not red!