Archive for the ‘PHP’ Category

again php captcha script

July 21, 2009 Leave a comment

You’ve already seen a post about captcha.If not i encourage you to see it.Thuough it is pretty simple captcha script.If you try to run that script you will notice that it is not like others where they have different type of background color,different type of font,noise.So in this post i will try to figure that.

First make a file name “captcha.php

now paste



function captcha($length) {

// generate a totally random string using md5
$rd = md5(rand(0, 999));

// We don't need a 32 character long string so we trim it down to 5 because md5 will return a long string
$code = substr($rd, 15, $length);

// Set the session to store the security code
$_SESSION["captcha"] = $code;

// Set the image width and height
$width = 200;
$height = 50;

// Create the image resource
$image = imagecreate($width, $height);

// Random RGB colours
$rgb1 = rand(0, 255);
$rgb2 = rand(0, 255);
$rgb3 = rand(0, 255);

$background = imagecolorallocate($image, $rgb1, $rgb2, $rgb3);
$text = imagecolorallocate($image, ($rgb1 - 60), ($rgb2 - 60), ($rgb3 - 60));

// Make the background colour
imagefill($image, 0, 0, $background);
for ($i = 0; $i < 10; $i++) {
$rx1 = rand(0,$width);
$rx2 = rand(0,$width);
$ry1 = rand(0,$height);
$ry2 = rand(0,$height);
$rcVal = rand(0,255);
$rc1 = imagecolorallocate($image,
//giving noise
imageline ($image, $rx1, $ry1, $rx2, $ry2, $rc1);

// Add randomly generated string in the image
for($i = 1; $i <= $length; $i++) {
$counter = rand(1, 2);

if ($counter == 1) {
$angle = rand(0, 45);
if ($counter == 2) {
$angle = rand(315, 360);

imagettftext($image, rand(14, 20), $angle, ($i * 25), 30, $text, "font/LucidaBrightDemiItalic.ttf", substr($code, ($i - 1), 1));

// Add a border
imagerectangle($image, 0, 0, $width - 1, $height - 1, $text);

// Tell the browser what kind of file is come in
header("Content-Type: image/png");

// Output the newly created image in jpeg format

// Free up resources


this code into that file.

You see “LucidaBrightDemiItalic.ttf”.I have this font in font directory.You can use ur font.And that will be your font style of captcha.But remember you have to put font file in the directory or Sub-directory where your php file will stay.

Now include this file in any other php file and make a call with


here 4 is the number of character you want to show.You can give your length of string.Here we use session to store the captcha string in $_SESSION global array.Since we have to use this later, to check whether the user submit the data or not.So that’s it.
And “Have a good programming

Categories: PHP


I’ve already learned many things after i’ve started blogging.Though some of them i understood but many of them i don’t.Many of them was not just only knowing things ,because those need to examine in a remote server where i always try to find things in my local server.I’ve tried for few free hosting space but they don’t have those things that i need.Though i have tried one.But what happened ,after a few days it blocked my account.what am i gonna do now.Now i have to try, to buy some hosting space for me.

Categories: PHP

create you own captcha

Somedays ago i’ve found a php captcha script from one of my php boss bhaia.But i don’t understand why his script does not work in my local server.But whatever i’ve made one of my own with the help of his script.
You can say it,2nd version of his script for me.

here what i’ve got.

$im = imagecreate(60, 30);
$RandomStr = md5(microtime());

$ResultStr = substr($RandomStr,0,5);
$bg = imagecolorallocate($im, 200, 255, 255);
$textcolor = imagecolorallocate($im, 200, 0, 255);
imagestring($im, 5, 6, 6, $ResultStr, $textcolor);

header("Content-type: image/jpg");

now name it captcha.php
now if you want to use it in a form or somwhere else you just write this:

<img src="captcha.php"/>


Categories: PHP

is this site live or dead

sometimes we need to import data from other site though we don’t know when we need to use their data from their site,will this site alive or dead?We can fix this problem via a php function called fsockopen,now i have a script that can work for you to understand more precisely


$up = @fsockopen("", 80, $errno, $errstr, 30);
echo "Wordpress is Alive";
echo "Sorry this site is not available now";

that’s it. Now check it out.

Categories: PHP

url minimizing and maximizing

July 1, 2009 1 comment

here is some interesting php code i have found from many of my resources,where i often goes for help like forums,blogs and others.This script helps you to make ur url tiny when you need to make ur url safe from bad guys.And also you can get ur real url using this script.Here it is

/* This function send a
request to with your real
url and return a tiny new url

function tiny_url($url){
return file_get_contents("" . $url);
$real_url = "";
$new_url=tiny_url($real_url);//now echo it if want to see
echo $new_url;

/* you can also expand this
url to real url by using

function real_url($tiny)
$real = get_headers($tiny,1);
return $real;
$tiny="";// you just place here what you've got in $new_url


echo $real_one['Location'];

Categories: PHP

For all new learner

June 29, 2009 1 comment

I post this for those who are new learner in web programming.I am a university student.Now in 2nd year 2nd semester.I started to learning php about one and half month ago.In my first year first semester,honestly i don’t know a shit of computer programming when
i’ve got chance in cse in my versity.What is programming and this kind of stuff i really don’t understand when the teacher lecture us.So i was very disappointed with that.I always ask to myself why i have write a b c in a compiler.So i sit with my book and my pc with very angrily.And i say to myself i have to , i have to understand this.And start to reading the book,after some days then i realize my improvment in programming lab classes,though i can not solve the problem in all classes but i can some.Now it’s a history to me.All i have to say that when you want to learn something don’t disappoint on yourself that why can’t you understand.I tell you i am learning php,sometimes i get bored to reading those english books for an hour to hour but i know when i will be in application of this it will not.Because i have already made a website for my club.And i tell you it was awesome to me.Now i am also try to learning ajax,jquery,cms and other stuff of web programming.So try not disappoint..keep it up. best of luck…..

Categories: PHP

Connect your site with mysql server

June 29, 2009 Leave a comment

Here is a simple [novice type]php script to connect your site with your mysql server.When i start to learning php i use this script to connect my site with my database server.It was so exciting that i can’t tell you.I insert something into a form and that store in database.It was feel like awesome to me.You know the first experience of success.hehehe..

So i give you that.

$db_host = ‘localhost’;
$db_user = ‘root’;
$db_password = ‘triadpass’;
$db_name = ‘db1’;

function connect_db()
global $db_host,$db_user,$db_password,$db_name;

$link = mysql_connect($db_host,$db_user,$db_password);
die(‘Not connected : ‘ . mysql_error());

$db_selected = mysql_select_db($db_name, $link);
if (!$db_selected) {
die (‘Error : ‘ . mysql_error());}
return $link;

Here mentioning that localhost was my mysql server address,username was root, password was triadpass and database was db1 for me not for you.You have your own server address,username,password and database name. After entering your server address,username,password and database name name tihs page as config.php.After naming it,you just have to include this page whenever you need.

Like it
$sql=”select * from table1″;
echo “query successful”;
ok done

Categories: MySql, PHP