RSSArchive for May, 2015

Implement captcha in PHP

As you know spamming can be a huge problem. You can prevent spamming in different ways. Either log the spammer ip and block it from further updates or you may use a captcha in your form. In this tutorial i would explain how to implement recaptcha using php. “reCAPTCHA is a free CAPTCHA service that helps to digitize books, newspapers and old time radio shows. Check out our paper in Science about it”.

1. GoTo

Click on “use reCAPTCHA on your site” and follow the registration steps. Once you are done, click on “My Account” in the left menu. a button appears.

Add a New Site

Click on it and add your website. When you finish, you will be redirected to a page contains your “Public Key” and your “Private Key”. Keep in your mind that your Private Key is must be kept as secret, so don’t share it with everyone. Also you need to have a key for every website. No matter if it is a sub-domain.

The package contains 2 files index.php and a lib file [recaptchalib.php]



<div align="center" style="margin-top:30px;">
<form action="" method="post">

$publickey = "XXXXXXXXXXXX";
$privatekey = "XXXXXXXXXXXX";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# are we submitting the page?
if ($_POST["submit"]) {
$resp = recaptcha_check_answer ($privatekey,

if ($resp->is_valid) {
echo "You got it!";
# in a real application, you should send an email, create an account, etc
} else {
# set the error code so that we can display it. You could also use
# die ("reCAPTCHA failed"), but using the error message is
# more user friendly
echo "You Missed it. Try it Again.";
$error = $resp->error;
<?php echo recaptcha_get_html($publickey, $error); ?>
<input type="submit" name="submit" value="submit" />

Note : Replace ‘XXXXXXXXXXX’ with your Private and Public Key.

You are done !

Convert Text to Image using PHP.

This tutorial would help you to convert a string to image using php. I have named the function as text2image as it makes some sense.

The main functions used in the following function is

1. imagecreate
2. imagecolorallocate
3. imagecolorallocate
4. imagestring
5. imagepng

The following code creates output

function text2image($string) {
// create a 100*30 image
$im = imagecreate(197, 30);

// black background and white text
$bg = imagecolorallocate($im, 0, 0, 0);
$textcolor = imagecolorallocate($im, 255, 255, 255);

// write the string
imagestring($im, 5, 10, 5, $string, $textcolor);

// output the image
header("Content-type: image/png");
return imagepng($im);

echo text2image(‘’);


Hope it helped you !

How to remove the Bom Sabado worm in Orkut.

Are you infected with “Bom Sabado” ?

Bom Sabado is a XSS (cross-site scripting) attack which floods your orkut scrapbook with “Bom Sabado” scraps.

The word “Bom Sabado” means “Good Saturday” in Portuguese, which is the also the official language of Brazil, one of the last remaining Orkut bastions in the world. Such XSS attacks have targeted Orkut in the past too.

Steps to remove Bom Sabado from your orkut account.

No need to change your account info or delete your account as the worm does not steal your account details . Just need to block it .

1. Use Mozilla add on AdBlock Plus . Download it from here.

2. After the browser restarts , Click on the ABP button on the tool bar and select preferences.

3. Click Add filter and enter ** .

Now you can safely login to Orkut and reset the changes made by the worm .

How to add “About the Author” Box in WordPress.

I had recently updated my blog theme and found that “about the author” box was missing at end of the post . I couldn’t find a good plugin to do the same but found a way to implement it manually .

This will require that you access 2 of your template files, however, very little coding is required.  Just copy and paste, unless you want to make further customization.

Step 1 : Edit single post page. [ single.php ]

Edit single.php [Single Post] page using appearance editor within your admin dashboard. Search for the <?php the_content(); ?> line of code, press enter to give some space then copy and paste the code below that line, then save :

<?php echo get_avatar( get_the_author_id() , 120 ); ?>
<h4>Article by <a href="<?php the_author_url(); ?>">
<?php the_author_firstname(); ?> <?php the_author_lastname(); ?></a></h4>
<p><?php the_author_firstname(); ?> has written <strong><?php the_author_posts(); ?></strong> awesome article(s) for us. <br/><br/><?php the_author_description(); ?></p>

Step 2 : CSS file

Copy the CSS code below to your style.css or custom.css file. This will control the background color, width and text alignment. You may change the color schemes as needed to fit your theme.

<pre>/* Author’s Bio Box */
.postauthor { background: #F5F5F5; border-top: 1px solid #e1e1e0; border-bottom: 1px solid #e1e1e0; overflow: hidden; padding: 1.5em; }
.postauthor img { border: 5px solid #e2dede; float: left; margin-right: 1.5em; }
.postauthor h4 { color: #666; font-size: 2em; margin-bottom: 5px; }
.postauthor p { color: #515151; font-size: 13px; margin-bottom: 12px; }</pre>

Step 3 : Author’s Bio

Add the author’s bio information in the About Yourself section in the wordpress dashboard.

Hope this tutorial was simple enough and very helpful !

Get the first image from a wordpress post and display it.

Hello friends , recently i came across some blogs that showed images under each post title on the index page . I needed to implement that in my blog , i found two methods to do it . Download a plugin named “Get The Image” and activate it or you can just copy paste the following code .

add the following code to functions.php

function catch_that_image() {
global $post, $posts;
$first_img = ”;
$output = preg_match_all(‘/<img.+src=[\’"]([^\’"]+)[\’"].*>/i’, $post->post_content, $matches);
$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
return $first_img;

Once done, you can simply call the function within the loop to display the first image from the post.

echo catch_that_image() ;

You are done !

Configure BSNL GPRS on Nokia 7210 Mobile manually | BSNL GPRS Settings

My Nokia 7210 was not receiving GPRS settings from customer care , even i searched on web for settings to set it manually but failed .

I am sharing the configuration that worked for me.

Following Configuration is for BSNL SOUTH ZONE

Step 1 : GoTo Menu – » Settings – » Configuration – » Personal config.sett. [ add new web in personal config.sett. ]

account name   –  bsnlnet
homepage   –
username    –
password     –
use pref.access pt.   –  no

& under access point settings fill in

proxy   –  disabled
data bearer   –  packet data [ try both ie, GSM/packet data ]

& under bearer settings fill in

packet data   –  bsnlnet
network type   –  IPv4
authentication type   –  normal
username   –
password    –

after entering the above details , activate it. [ you can activate it under Menu – » Settings – » Configuration – » Personal config.sett. ]

restart your mobile after activating the settings . you are done ! Happy Browsing .

Image Protection Code using PHP | HTML | Javascript

Hai All ,

I implemented image protection in one of my latest work. Its pretty simple and effective so i am sharing with you.

Check out the demo and try the following :-

1. Try dragging the image to the Navigation Bar.

2. Right Click and Try viewing the image.

3. Take the source and click on the src of img tag.

Step 1 : Create a page named index.php

$page = $_REQUEST[‘p’];
if($page == ‘sImage’)  {  include(‘image.php’); }
else { echo ‘<img src="index.php?p=sImage" />’; }

Step 2 : Create a page named image.php

$imageName = "logo.jpg";
$img1 = imagecreatefromjpeg($imageName);
$img2 = imagejpeg( $img1 );

Note : You can save the image by right clicking -> Save Image as [ you can protect that too by disabling right click action using javascript :) ]

There are many other ways to hack the code. But this would save you from Newbies.

You are done !