Twitter bot in php with oAuth support

For last couple of days, I was looking into twitter API. One day I asked Lenin vai about a bot he made. He suggested me a Twitter bot. I was so excited at the very beginning. But when I had started I gone through some new features which I didn’t know and of course sometimes silly things give us so much pain 😛

About Tweet Bot:

The bot collects data from one or more locations and then tweets those one by one. Very simple php script. Usable with any website or blog and even any person at Twitter.

Tweet Bot Features:
  • oAuth supported
  • Parses feed with simple feed parser
  • Formatting links by shortening url
  • Format large title
Setting up Tweet Bot

Register application from here. For oAuth support I’ll be using Abraham William’s oAuth Library. Download the Twitter oAuth Library from github. The bot will be getting feeds from RSS. For that we need a parser. So, here we’ll be using Simplepie to parse RSS feed. Download the parser from here.

I always prefer to make a configuration file, just to keep the code clean and ready to use any time.



/* Change this url as needed */
define('FEED_URL', '');

Now let’s make our hand dirty with some coding 🙂


Connect to twitter via Abraham’s oAuth Library


Setup Simplepie to parse RSS feed.

$feed = new SimplePie();

We need to save the parsed link so that we can prevent the bot tweeting the same thing more than once. Twitter has word limitation of 140 words. So, the bot parses the title as well as the link. It always matches the latest link with the last tweeted one.

/* find the total number of available feed */
$max = $feed->get_item_quantity();

/* Get last tweeted data */
$last_saved_tweet = file_get_contents('last_tweet');

/* Get the first item on the feed */
$item = $feed->get_item(0);

/* permalink of the first item */
$itemlink = $item->get_permalink();

/* save the permalink into file */
file_put_contents('last_tweet', $itemlink);

/* title of the first item */
$itemtitle = $item->get_title();

/* length of the item title */
$titlelength = strlen($itemtitle);

if ($titlelength > 110) {
    $itemtitle = substr($itemtitle, 0, 107) . "...";

if ($itemlink != $last_saved_tweet) {

    /* shorten the url with tinyurl */
    $shortlink = file_get_contents("" . $itemlink);

    /* Update status with Abraham's oAuth Library */
    $connection->post('statuses/update', array ('status' => $itemtitle . " " . $shortlink));

So, now the Tweet Bot is ready to shoot! 🙂


Facebook Application Setup

Making web applications and desktop applications are something like cooking food. To cook a delicious food is not always necessary when we are learners. To cook foods the first thing we need is to know the fundamental tools we need. Then we might need a setup to make the food eatable. Then light up your burner and start cooking. The taste is yours!!!

Here I am going to discuss about basic facebook application setup on Facebook Platform.

Types of facebook application?

There are basically two types of applications on FB.
1. iFrame

How facebook application runs on facebook platform?


another form is,


Go to Account -> Application setting

I assume that you have a developer account. If not, follow the necessary steps to make one.

Then choose Developer from the menu and select  + Set Up New Application. Here you’ll be prompt to name your application. Give a name and choose Agree.

Now, you’ll see something like this. These are the basic information of your application.

Essential info
Essential info

Now select the canvas tab. Remember this is the crucial part of your application. Canvas page URL, is the address of your application on Facebook Platform. Canvas Callback URL, where application is hosted.

canvas url
canvas url

Canvas Setting, here we are to develop a iFrame application. So, choose iFrame from the option. Choose other options as you need.

Save settings and TADAAAA!!!!!!!!!!!! This is enough for a simple application to go on.

Send SMS with GrameenPhone API and PHP

To work with Aloahbei platform, first edit the .wsdl file for SMS which is given on the Aloashbei site. Or you can download it from here.

First, make a config.php file.

$soap = new SoapClient("");

$var['registrationID'] = "******";
$var['password'] = "****";
$var['sourceMsisdn'] = '88017********';
$var['smsPort'] = 7424;
$var['msgType'] = 4;
$var['charge'] = 0.00;
$var['chargedParty'] = '88017********';
$var['contentArea'] = 'gpgp_psms';

Now, make the main index.php file put the number and message into the $var array and call sendSMS api.

$var['destinationMsisdn'] = '88'.$_POST['number'];
$var['msgContent'] = $_POST['msg'];

$result = $soap->sendSMS( array ("SendSMSRequest" => $var) );

Download full code

Install phpmyadmin in ubuntu

In the previous article you’ve seen how to setup a LAMP server. Now if you want to install phpmyadmin open your terminal and type
sudo apt-get install phpmyadmin
follow the screen.

Now, open browser go to http://localhost/phpmyadmin/

you are done with your phpmyadmin installation. now, login with the password you provided earlier.

Install LAMP on ubuntu

Installing LAMP(Linux, Apache, MySQL, PHP) is not that tough now-a-days.

The easiest way
First open the synaptic manager with sudo synapti
then Edit ==> Mark Packages by Task
select LAMP server from the list and click OK.

Another easy way
go to terminal and type
sudo tasksel

press space bar to select and then tab to <ok>
Follow the screen.

One line command setup
go to terminal and type
sudo apt-get install lamp-server^
N. B the character ‘^’ is not a typo
Follow the screen, it’ll ask to change password for the root user of MySQL database.

Now. test Apache. Open a browser and type http://localhost/

if you see this, you are done with you apache installation.

test PHP installation. open terminal and type
sudo vim /var/www/test.php
save the file.
again, sudo /etc/init.d/apache2restart
now, open browser and try http://localhost/test.php

you see this, means your PHP installation is completed.

Test MySQL setup
go to terminal and type
mysql -u root -p

you see this, ahhhh….you are done with the famous LAMP installation 😀

For phpmyadmin setup try this

WordPress test data .xml import

I was developing wordpress theme, but while it was time for testing, it was quite annoying as lots of posting and commenting were needed. Though Lorem ipsum was there to help, but making comments and posting again and again was quite boring. The I found some test data, which solved my problem just in a second 😀

click here to download the test data, extract it and then import it into your WordPress dashboard. You are done 😀

If you are completely new with .xml importing then follow the following steps(for WP ver. 2.9.2):

  • Login to your wordpress dashboard (e.g
  • select import from Tools
  • choose the WordPress option from the table
  • and then finally upload your downloaded file and Have Fun!

If you face any problem regarding this topic feel free to contact me.

CSS Framework is strong CSS framework. When I first used this tool I found it quite complicated to understand, but gradually I got know the uses of this nice framework. Here I’ll be sharing my experience on this amazing tool for the beginners.

Download the file from and extract it. Then go to the copy folder and open the demo.html is your favorite IDE(notepad, textwrangler, netbeans etc) and start editing 😀

If you open the demo.html in your browser you’ll find lots of dummy layouts to choose your own. Find the layout you need, and remove the others. The css code is written in such a great organized way, so that will understand it very soon. I’ll suggest you to start with the uncompressed folder, where you will find the .css file more understandable.

Layouts are organized into 3 different ways, container_24(which can be found in a separate .css file), container_12 and container_16. The number after the container stands for the number of usable grids using that certain container. Then, there are grids, grid_1, grid_2, … , grid_16. These are the selectors of the specific fields with specific positions and sizes. alpha and omega are the tools to choose margin positions respectively left and right. prefix and suffix are used for left and right padding. push and pull are used to specify the exact position specifying the pixels into positive and negative.

See sample code comes with demo.html, start editing and make your own constant CSS layouts.