Do you want to upgrade your site with twitter so that you can upgrade your messages each time through the site only? What big deal about that- You may ask. Well how about doing it without doing it without downloading any application! How about writing a php code which will help you to upgrade your tweets simply? Here is how.

Code

$username = 'myUserName';
$password = 'myPassword';
$status = 'This is a new Tweet!';

if ($status) {
$tweetUrl = 'http://www.twitter.com/statuses/update.xml';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");

$result = curl_exec($curl);
$resultArray = curl_getinfo($curl);

if ($resultArray['http_code'] == 200)
echo ‘Tweet Posted’;
else
echo ‘Could not post Tweet to Twitter right now. Try again later.’;

curl_close($curl);
}

Note:

  • Change $username to YOUR username
  • Change $password to YOUR password
  • Edit $status to the Tweet that you want posted.

So this is it. Additionally you can add some more Javascripts that counts the amount of characters in the Tweet field and such stuff.

Happy twittering.

[Source: brownphp.com]