How to Tweet Using PHP without any Twitter App!

By Angsuman Chakraborty, Gaea News Network
Tuesday, January 13, 2009

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.


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

if ($status) {
$tweetUrl = '';

$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’;
echo ‘Could not post Tweet to Twitter right now. Try again later.’;



  • 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.



July 22, 2010: 4:19 pm

Why don’t you just point to the original post and script instead of passing it off as your own you stinking spammer. By the way, I’m just a guy on the internet that hates this kind of crap. The brown guys are #1 in the results so that’s right in my book.

May 22, 2010: 3:33 pm

I want to change the ‘from name’
Now twitter shows ‘from api’ but i want my own website as referal. like from as example, just like from: twaiter!

Anybody can help?


May 21, 2010: 12:31 am

I hope it will help me out

April 15, 2010: 6:44 pm

This is a great code snippet to get tweeting fast.

Since you’re transmitting sensitive data (a password!) you should opt to use the SSL protected URL
$tweetUrl = ‘’;

April 8, 2010: 7:15 pm

I dont understand article. anyone help me out a bit

July 16, 2009: 12:36 pm

The tweeting script worked a treat! many thanks.

I made small modifications and the rendering on the page made a bit of a mockery of the left and right quote character.

I modified so that all fields were $_POST['fieldname']; and $status = stripcslashes($_POST['blah']);
so now I carry a little html page on a pen drive with a input type=hidden name=blah value=blah> etc.

So I tweet pretty securely right off a pen drive which remains with me.


will not be displayed