Image Creation on the lfy with some number in it

Hello Fellow Coders,

I would like to ask if someone has already created a php script that is used on most of the registration and sign up forms these days where the applicatant is asked to enter the numbers as shown in the picture on the side to prevent the misuse of the registration system.

I hope I have been able to describe exactly what I am looking for. Please feel free to share your PHP codes :)

Have a Good Day :)

Ajay Chadha
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Ajay,

The basic process to do this is to first create a random string to use for the verification and then use the GD Library (which you will be required to have installed on your server) to create the image and display it. You can then cross reference the string entered by the user with the string generated and check that they match.

There are a few good examples of the process on the web, "php image verification" is a good search term. One example of which is:

That code would go in a file called something.php and would be loaded into your form using <img src="something.php">

You might want to put the string generated in a session so it can be referenced later so you would need session_start(); at the top of your file, then to save changing the code too much in the example link you would replace:

$string = substr(md5(time()),$start,$characters);


$_SESSION['veri'] = substr(md5(time()),$start,$characters);
$string = $_SESSION['veri'];

Then once they have entered the number and posted the form you can check that it matches the session value, adding session_start(); at the top of the file again to initialize the session, then for example:

if ($_POST['your_inputs_name'] == $_SESSION['veri']) {
 // they have entered the right string
Also, in this example its just a basic output of the characters, some verification images also include lines across the text etc. You could recreate similar things using the available functions eg:

You could also make use of the rand function ( to randomly position the line each time.

Full reference of the image functions:
Try this,  and refresh page you observe different numbers

header ("Content-type: image/png");
$im = @imagecreate (200, 200) or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 233, 14, 91);
imagestring ($im, 1, 5, 5, implode(" ",preg_split("//",(rand(200,36000)))) , $text_color);
imagepng ($im);
imagedestroy ($im);
AJAY CHADHAAuthor Commented:
Where to get the GD library from?

We are using Windows Express Installer version of the PHP and GD library is not installed with that.

so, from where we can get the library, what files are required to be installed and where?
The GD site is

But apparently the dll you need they are supplying is not currently for php so you could do this...

Go to and download the windows zip package and grab the gd dll out of it
(for the php 5 package its in the folder called ext and is named php_gd2.dll)

You then need to copy that dll into your extensions folder, on Windows i think it is the Windows directory, check what it is specified as in the php.ini file. You also need to uncomment the GD extension in the ini file, this line:


remove the ;

You will then need to restart your web server.

To check its installed correctly create a test file containing <?php phpinfo(); ?> and access it and look for the section about gd, you should see various settings all flagged as enabled.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.