Update Twitter Status with PHP – Most Simple Script!

Every web developer in this universe would like to have a Twitter application on his website. Here is the simplest possible PHP application that allows you to update your Twiter status from your webpage only. The script is extremely simple to use.
Before running the script you have to enable curl service in your PHP installation.

cURL stands for Client for URLs. It allows us to transfer files having URL syntax. It supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE.
To enable curl library with XAMPP we need to modify the php.ini files in our xampp folder.
1) Locate the following files:
C:Program Filesxamppapachebinphp.ini
C:Program Filesxamppphpphp.ini
C:Program Filesxamppphpphp4php.ini
2) Uncomment the following line on your php.ini file by removing the semicolon.
3) Restart your apache server.
4) Check your phpinfo if curl was properly enabled.

 Just checkout the live demo…

Live Demo Live Demo

PHP Code

/* ---------------------------------------- */
// Change these parameters with your Twitter
// user name and Twitter password.
/* ---------------------------------------- */
$twitter_username =$_POST['twitter_username'];
$twitter_psw =$_POST['twitter_psw'];
/* ---------------------------------------- */

/* Don't change the code belove
/* ---------------------------------------- */
$twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message);
/* ---------------------------------------- */
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<body style="text-align:center; ">
<h2>Post a message on Twitter</h2>

<!-- This is the form that you can reuse in your site -->
<?php if(isset($_POST['twitter_msg']) && !isset($error)){?>
<div class="msg"><?php echo $twitter_status ?></div>
<?php } else if(isset($error)){?>
<div class="msg">Error: please insert a message!</div>
<?php }?>

<form action="insertTwitterMsg.php" method="post">
<label>Twitter Username : </label><input type="text" name="twitter_username"><br />
<label>Twitter Password : </label><input type="password" name="twitter_psw"><br />
<div style="background-color:#ffcccc;" ><p style="color:#FF0000; font-size:10px;">Your login details are not stored! Feel safe.</p></div>
<p><strong>What's happening?</strong></p>
<textarea name="twitter_msg" id="twitter_msg"></textarea><br />
<input type="submit" name="button" id="button" value="post" />
<!-- END -->


CSS Code

body{font-family:'Lucida Grande', Verdana, sans-serif;; font-size:14px; color:#666666; width:500px;}
div.msg{background:#FFFFCC; margin-bottom:10px; padding:4px;}
input{border:1px solid #2BAE9E; color:#444444; padding:3px; font-family:Georgia, "Times New Roman", Times, serif; -moz-border-radius:6px;}
#twitter_msg{border:1px solid #2BAE9E; color:#444444; padding:3px; font-family:Georgia, "Times New Roman", Times, serif; height:40px; width:400px; -moz-border-radius:6px;}
#button{background-color:#C8F0EF; border:2px solid #2BAE9E; padding:3px; -moz-border-radius:6px; float:right; margin:5px 45px 5px 5px;}

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.

Website: http://www.webspeaks.in/

3 thoughts on “Update Twitter Status with PHP – Most Simple Script!

Comments are closed.