Cazpa.com PHP Developer & Website Designer

24Oct/091

Update Twitter From Your Website (HTML form)

Here is a small script that allows you to post updates to twitter from a simple HTML form on your website.

First thing you need is the form, this is a simple HTML form, very easy to add to your existing website:

<form name="form1" method="post" action="twitter.php">

Now for the script, just copy and paste this code into a blank document and save as twitter.php, you can name it what you want just remember to change the form action variable:

$username = ($_POST['t_user']);
$password = ($_POST['t_pass']);
$message = ($_POST['t_update']);

$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)) {
    echo 'message';
} else {
    echo 'success';
}

And that is it, if you want to set the username and password then all you need to do is change:

$username = ($_POST['t_user']);
$password = ($_POST['t_pass']);

// to

$username = 'yourusername';
$password = 'yourpassword';

http://cazpa.com/wp-content/plugins/downloads-manager/img/icons/winzip.gif download: Web To Twitter (957B)
added: 24/10/2009
clicks: 137
description: Post updates to Twitter from your website (Script)

No related posts.

About Daniel Smith

I am the boss around here, if you need anything then send me a message :))

Popular Content & Keywords

depositfiles hack,add update delete in php,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in,php tutorial deutsch,php define variable,,rails vs php performance,php add update delete,add update delete records from sql server using php,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content,tutorial create contact form in dreamweaver php,ruby on rails vs php 2010,php tutorial // user registration w/ sql,send emails with a web form: php scripting,
Comments (1) Trackbacks (0)
  1. hi daniel y i when i use your code it get fail? help me.. i like your simple code:)


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.

Powered by WordPress Lab