I have an application ive built that users can register and link their twitter account.
If somebody creates a user for spam purposes however Twitter then deletes this user, they still stay on my site however. If another user then tries to follow them I bounce back a message saying user is no longer valid only this has become a serious problem and there’s a lot of spam accounts.
My current solution is when the page loads, with jQuery check to see if the twitter users image loads and if not set that user to display none.
Im wondering however, is there a way to check BEFORE outputting my page, so this way my users arent presented with a list of users, that when the page loads X of them dissapear, but a list of users who are all active?
Thanks
This is the php I have on my page, I know its old but is there a way to check if the user exists with Twitter and mix it with what I currently have?
Sorry im very new to PHP!
$rs = mysql_query("select produgg_users.id, twitterUser, coff, credits from produgg_users where twitterUser != '' and active !='' and credits >= coff and
produgg_users.id IN (select concat_ws(',', id) from produgg_users where credits > 0 and id != ".$usersClass->userID().") and produgg_users.id NOT IN (select concat_ws(',', followedID) from produgg_activity where followerID = '".$usersClass->userID()."') and produgg_users.id NOT IN (select concat_ws(',', userid) from produgg_featured) ORDER BY coff DESC LIMIT 30;") or die(mysql_error());
$nr = @mysql_num_rows($rs);
if($nr != 0) {
print "<h2>More Friendr Users!</h2><div>";
while($row=@mysql_fetch_object($rs))
{
$divLeft = '<div class="user-box" id="thediv_'.$row->id.'"><div class="twithandlepic"><img src="http://api.twitter.com/1/users/profile_image/';
$divRight = '<div class="twithandle">';
$clearDiv = '<div style="clear:both;"></div>';
$row->coff = $row->coff - 1;
print $divLeft.strip_tags($row->twitterUser)."?size=bigger\" style=\"width:73px; height:73px;\"/><br \/>".$row->twitterUser.$divRight."<a href='javascript:void(0);' id='vote_$row->id' class='getPoint'>Get $row->coff <input type='hidden' value='$row->coff' class='credoff' name='credoff'/> credit(s)</a><br /></div>$clearDiv</div></div>";
} print "</div>";
echo " <a href='earn-credits.php' class='refreshlist'>Refresh</a>";
}else{
print "<p>No twitter users to show</p>";
}
You can just send a request to
twitter.com/usernameand look at the response code: 200 if the user exists, 404 if they don’t. For example, try http://twitter.com/somefakeperson and you’ll get a 404.Using CURL it’d look something like this:
As an aside, it might also be good to send an update back to the DB any time you hit an invalid user to either remove or flag the user somehow. You could then filter out those users in the future right at the DB level.