PHP

PHP Validate Twitter Username Example

If you want to validate Twitter username using PHP i.e check whether its available for registration or not, this can be easily achieved using CURL. The following function will check whether twitter username exists for registration or if it is already registered.

How to Validate Twitter Username using PHP

Use the following code to validate Twitter Username using PHP:

<?php
function validate_twitter_username($username)
{
$twitter_url='http://api.twitter.com/1/users/show/'.$username.'.xml';

$init = curl_init();
curl_setopt ($init, CURLOPT_URL, $twitter_url);
curl_setopt ($init, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($init, CURLOPT_NOBODY, 1);
curl_setopt($init, CURLOPT_HEADER, 1);
curl_setopt($init, CURLOPT_RETURNTRANSFER, true);

curl_exec($init);
$result_header = curl_getinfo($init, CURLINFO_HTTP_CODE);
curl_close($init);

// IF username does note exist, then it means its avilable for registration
if( '404' == $result_header )
{
return 'Username is available.';
}
else
{
// This means username is already taken
return 'Username already taken.';
}
}

//Enter the username you want to check below and that's it.
$username = 'extreme';

echo validate_twitter_username($username);
?>
That’s it!

Do you know a simpler way to validate twitter username? If yes, please share it with us in your comments below.

13 Comments on PHP Validate Twitter Username Example

  1. 1

    you might have an amazing blog here! would you wish to make some invite posts on my weblog?

  2. 3

    That is the suitable blog for anyone who needs to seek out out about this topic. You understand a lot its virtually arduous to argue with you (not that I actually would want…HaHa). You definitely put a new spin on a subject thats been written about for years. Nice stuff, simply nice!

  3. 5

    When I initially commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the identical comment. Is there any means you may take away me from that service? Thanks!

    • 6

      You have either already unsubscribed or not subscribed at all. If you still continue to experience such an error, please send the screenshot of the subscription message that you received and I will do the needful.

  4. 7

    Spot on with this write-up, I really assume this web site needs rather more consideration. I’ll in all probability be once more to read much more, thanks for that info.

  5. 8

    Awesome website! How did you get this design?

  6. 10

    I genuinely love the theme on your site, I run a internet web site, and i would adore to use this theme. Is it a free of charge style, or is it custom?

    • 11

      Hi,
      This is a totally custom theme that we have built from scratch. If you want to get custom theme created for your own WordPress blog, simply contact us and we will help you out.

  7. 12

    There are some fascinating time limits on this article however I don’t know if I see all of them middle to heart. There’s some validity but I will take hold opinion until I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as nicely

  8. 13

    I’m very pleased with the articles on your blog. I recieve numerous tips which helped me to.

Leave a Reply to Charles Boroski Cancel reply

*

*