Cazpa.com PHP Developer & Website Designer

24Oct/090

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: 85
description: Post updates to Twitter from your website (Script)

About Daniel Smith

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

Popular Content & Keywords

rails vs php performance,php define variable,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in,add update delete in php,php tutorial // user registration w/ sql,ruby on rails vs php,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content,php define href with variables,twitter api php tutorial,facebook jsonwrapper,warning: mail() [function mail]: smtp server response: 554 the message was rejected because it contains prohibited virus or spam content in on line 15 error,adding records to a mysql database using php,web server administrator tutorials youtube,contactformprocess php,facebook jsonwrapper php
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.

Powered by WordPress Lab