This tutorial will show you how to make a basic math CAPTCHA validtion form.
This requires that you have the GD library for PHP installed to work.
This tutorial requires 2 files, login.php and action.php.
The first step is to create a sub-folder to store the temporary images, for the purposes of this tutorial,this folder should be called images. Now upload a image in there called verify.php and chmod just that image(not the folder) to 777 so that image can change as our functions generate new images.
Ok, after you've done that, we can get to the code:
The first step is to create the image, the ImageCreate function in php does just that. The 200 and the 40 are the dimensions of the image created. The image created is stored in $img. $white and $black define the text color of the numbers and the background color of the image respectively. In this tutorial, the background color is greenish and the text is black for easy contrast.
Next we set the random seed with the srand function. We do this by time so when we do call the random function, we get a different number each time.
Then we generated two numbers between one and ten with the rand() function and store them in $string and $string2. In $string3, we combine them to make the actual text on the image. $string3 is not actually the sum of the numbers, it is just the text string and is not numeric. $thevalue is the actual sum of the two numbers when they are added. There's no real reason to set $verification equal to $string3 because we can just directly use $string3 but I do it by habit.
Fill the image with our defined ours and stores the image into images/verify.jpeg.
Now we have to write the form. Its a pretty basic form. We store the actual value of the answer in the form field 'hidden value', which is a non-visible hidden field. The answer to the math question the user types in is $yourcode. Of couse we have to display images/verify.php so people can actually see what the math question really is.
Now we move to action.php:
Code:
CODE
<?php
if(isset($_POST['submit']))
{
$yourcode=$_POST['yourcode'];
$hiddenvalue=$_POST['hiddenvalue'];
if($yourcode==$hiddenvalue)
{
print "Correct, put your content here";
}
else
{
print "You verification code is not right. Please go back and try again.";
}
}
?>
This is a very simple file that basically gets the two variables from the two input fields from login.php and compares them to see if they are equal. If they are equal, it goes to the "You are correct" case, if they are not equal, it goes to the "your code is incorrect case". In a real application, you would put your actual content in the "You are correct" case and a redirect back to some other page in the "You are incorrect" case.
Notice from BuffaloHELP:
It is imperative that you use the proper BBcode when listing a programming language. Copied from source Warning.
Hello, I've been looking for a way to add this type of image validation to a form on my company's website. I'm kinda new to this type of advanced code, so I don't know how to go about adding the code to the existing form and there's some things you have in your tutorial that I don't quite understand.
"Now upload an image in there called verify.php and chmod just that image(not the folder) to 777 so that image can change as our functions generate new images."
How do I create a .php image and what do you mean by "chmod" just that image?
Chmod is a unix command that changes permissions of files. If the server that your website is on is unix you should be able to ssh into it, and chmod the file to 777. Otherwise you could use ftp to do this, or even write a php file to change the permissions of the file. For example, you could write this in a php file:
CODE
<?php chmod("verify.php",0777); ?>
upload it to the same directory as verify.php and run it once to change it.
QUOTE (jeffny01 @ May 22 2007, 09:36 AM)
How do I create a .php image
A php image really isn't that much different than a php file. The difference is in the headers that it outputs. For example, at the top of a php file that I want to output an image of type jpeg, I would add this header:
CODE
header("Content-type: image/jpeg");
Then once you have an php image you can use GD library to draw shapes, text, and other images to the canvas to be outputted to the user.
Looks like a nice scripts, I didn't try if it works, but I can suggest that a better way would be to create a little bit more complex things with math, because you're only using + to get the sum, I would suggest to make a random question of subtraction, multiply too, well I guess the script will be more complex, but it will be a better way to do it, also for fun you could add sqrt() for numbers only 4,16,49 and no more.. That it would be easy for a human to enter the true code..
A bot to bypass this could easily be made, seeing as you have the answer in the source. You would probably have the same level of security if the question was text.
This tutorial will show you how to make a basic math CAPTCHA validtion form.
This requires that you have the GD library for PHP installed to work.
This tutorial requires 2 files, login.php and action.php.
The first step is to create a sub-folder to store the temporary images, for the purposes of this tutorial,this folder should be called images. Now upload a image in there called verify.php and chmod just that image(not the folder) to 777 so that image can change as our functions generate new images.
Ok, after you've done that, we can get to the code:
The first step is to create the image, the ImageCreate function in php does just that. The 200 and the 40 are the dimensions of the image created. The image created is stored in $img. $white and $black define the text color of the numbers and the background color of the image respectively. In this tutorial, the background color is greenish and the text is black for easy contrast.
Next we set the random seed with the srand function. We do this by time so when we do call the random function, we get a different number each time.
Then we generated two numbers between one and ten with the rand() function and store them in $string and $string2. In $string3, we combine them to make the actual text on the image. $string3 is not actually the sum of the numbers, it is just the text string and is not numeric. $thevalue is the actual sum of the two numbers when they are added. There's no real reason to set $verification equal to $string3 because we can just directly use $string3 but I do it by habit.
Fill the image with our defined ours and stores the image into images/verify.jpeg.
Now we have to write the form. Its a pretty basic form. We store the actual value of the answer in the form field 'hidden value', which is a non-visible hidden field. The answer to the math question the user types in is $yourcode. Of couse we have to display images/verify.php so people can actually see what the math question really is.
Now we move to action.php:
Code:
CODE
<?php
if(isset($_POST['submit']))
{
$yourcode=$_POST['yourcode'];
$hiddenvalue=$_POST['hiddenvalue'];
if($yourcode==$hiddenvalue)
{
print "Correct, put your content here";
}
else
{
print "You verification code is not right. Please go back and try again.";
}
}
?>
This is a very simple file that basically gets the two variables from the two input fields from login.php and compares them to see if they are equal. If they are equal, it goes to the "You are correct" case, if they are not equal, it goes to the "your code is incorrect case". In a real application, you would put your actual content in the "You are correct" case and a redirect back to some other page in the "You are incorrect" case.
Notice from BuffaloHELP:
It is imperative that you use the proper BBcode when listing a programming language. Copied from source Warning.
Actually i appreciate your work dude and i am shortly going to launch my new website where i am going to use many of the scripts which are very antique. I mean i am not going to use any script which is already very famous and is used by thousands of member across web. I am searching for many of these type of scripts. I would be glad to have some more scripts like this one. Thankyou....
I hope you don't mind but I plan on using this to dissect and learn more about php and how it works. It seems to hit on a lot of the parts of the language(generation, comparison, etc.) so it should be helpful to me.
I'd have to say that the script seems pretty nice. Shame it wasn't their own creation, but ah well. Anyway, I'll admit to being completely unaware that PHP could be used to create images prior to reading this. Well...I was "aware" in the context that I'd seen image validation before, but not "aware" as in seeing how simple it appears to do. Actually a pretty handy thread, considering I've been trying to find ways to manipulate images in a consistent way (adding an icon to the top left), and this could have pointed me in the right direction. Cheers.
To avoid bots reaching the real captcha code ( or at least make it harder for them ) you have to use the php function to create a gif from an image and the numbers you used. It isn't foolproof, but a common bot won't be able to go through it.
In case you haven't noticed, I have a different Avatar display on the Forum each time the page
is refreshed. /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif"
/> For those of you who might want the script to do that, here is the one I am using: HTML
$filesp = glob('*.png'); if(empty($filesp)){ echo 'no images found...die br >';
die(); } else{ foreach ($filesp as $file) { $img_array = trim($file); } } shuffle($img_array);
//select image at random header("C o n t e n t{dash}t y p e: image/png"); // replace th....
OK, I recently had the need to create a PHP CAPTCHA system for a friend, and I am sharing this as a
tutorial with the good people here at Trap17. I am sure you have all seen a CAPTCHA before (although
you may not have known what it was called). They are the little codes you often have to enter when
you register with a site, to make sure you are a person and not an automated script. Some common
examples look something like this: My system doesn't really do anything as fancy, but I
think that it is slightly more readable that some of those that get generated. Every....
As reported in another posting , there is an Image Gallery named Hoverbox from the Sonspring site
which is a pretty cool display method using CSS to have Thumbnail pictures double their size by
hovering over them. I liked the css included in the original Tutorial as found on the Sonspring
site , but I knew there was more than one use for the Hoverbox and took it upon myself to explore
the use of the Hoverbox on a site I webmaster. One thing that wasn't right was having to
hardcode the image tags, so the first version I wrote used php to fill the Hoverbox by rea....
Place this code between and tags. CODE function makevisible(cur,which){
strength=(which==0)? 1 : 0.2 if (cur.style.MozOpacity) cur.style.MozOpacity=strength else if
(cur.filters) cur.filters.alpha.opacity=strength*100 } // --> Place the following code within
all of the image tags you'd like the effect to be applied. CODE
style="filter:alpha(opacity=20);-moz-opacity:0.2" onMouseover="makevisible(this,0)"
onMouseout="makevisible(this,1)" And your image tag might look like that. CODE
"yourimage.gif" in last code change to your ....
Image Shack Mod For Invision Power Board ''These instructions will help you to install
'ImageShack on your Site' into the reply, quick-reply, and post-new-thread sections of your
Invision Power Board, thus giving your visitors the ability to upload images directly. After upload,
they may paste the images directly into their post box.'' CODE These instructions will
help you to install 'ImageShack on your Site' into the reply, quick-reply, and
post-new-thread sections of your Invision Power Board, thus giving your visitors the ability ....
I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
around to installing it. I have been practising with Visual Basic and making some rather basic
programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
to create a basic image viewer, and I will try to explain each step from beginning to end as clear
as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so....
Those of you that don't know what is meant by 'hotlinking', it is when someone directly
links to an image on your site so it will display on their site. This is what is called
'bandwidth theft' and being as accounts here have a limit on bandwidth, your bandwidth limit
could be exceeded by someone else hotlinking to your images. As most users of cPanel will know,
there is an option to disable hotlinking of images in the "Site Management Tools" section.
However, this disables hotlinking to all directories, what if you only want to disable hotlinki....
Tutorial: Image Rollovers w/ Javascript, by Rob J. Secord, B.Sc. (SystemWisdom) See a
working Sample of this Script! Download a ZIP containing all working files in this tutorial!
Note: If you are not interested in reading this entire tutorial and/or have a basic understanding of
the underlying concepts, you may safely skip to the Implementation section to get the code!
Description : A Dynamic Image Rollover Script tested to work in 4 major internet browsers: MSIE,
FireFox, Netscape and Opera. Using only Javascript combined with regular HTML Images ( ....
How To: Change An Image When A User Clicks On It using both php and javascript - a powerful
combination I have seen quite a few how tos offering a method of doing this but none of which
resembled my method of making use of both php and javascript. This code is fairly repetitive and
most of the functions are easy to pick-up if you haven't heard of them before. Here it is...
Create your two images. Call them anything you like, you'd just need to change their filenames
in $imgano $imgayes. In fact with this script you can easily create more than one pair....
Tutorial: Extending the Image Preloader with PHP4, by Rob J. Secord, B.Sc. (SystemWisdom)
Second Tutorial in a Series of 2 Tutorials! Be sure to have read the First One here: "Image
Preloader With Progress Bar Status" See a working Sample of this Script! (Note: Preloads 100
images, some images are larger than others, and may take awhile for some people.) Description :
A Tutorial for Extending the Image Preloader with PHP4 to Dynamically Populate the Array of
Preloaded Images. This tutorial is the second in a series of 2 tutorials, and assumes that y....
Tutorial: Image Preloader with Progress Bar, by Rob J. Secord, B.Sc. (SystemWisdom)
Description : A Tutorial for a Client-Side Image Preloader with Dynamic Real-Time Progress Bar
Indicator written in JavaScript! Tested to work with 4 Major Internet Browsers: Firefox, MSIE,
Netscape, Opera (Complete sample solution provided at end of tutorial, just put it on your
web-server, add your images and go!) Intended Audience : Beginner to Intermediate Web
Developers. Although this tutorial will cover some advanced aspects of JavaScript, I will try to
explain it all ....
Here is a way of having roll over image links without preloading images by using CSS and a table.
It's very useful for a list of links as in a side bar menu or header. It also solves not having
to make a seperate image for each different link by placing the desired text over the image. 1.
First you need an image which comprises of the main link image, the 'mouse over' image link
underneath plus you can have another for visited links. As for most roll over images, the images
should be the same size. The above example - button.gif is 100x60px with each lin....
This tutorial will teach you the basics of making abstract images in 3D studio max. In this example,
I used a simple sphere, and applied the “Noise” modifier. Then, I applied a transparent, blue,
plastic-like material to spice up the whole thing. Let’s start. First, make a sphere by selecting
the “Sphere” button in the “Standard Primitives” section, and draw somewhere in the center of the
perspective view. We will set the size of the sphere later on. The sphere I made looks like this,
yours can be different in size and color, but the only thing that is important is to....
First, It's really confusing. Do you know any tutorials on Image Manipulation on PHP?
Here's another simple one: 1. Create a 5 image. 2. Rename them to something like:
image1.jpg; image2.jpg; and so on... 3. Create your PHP file (rotation.php) 4. Enter the
following code: CODE header("content-type: image/jpeg");
readfile("image".mt_rand(1,3).".jpg"); ?> 5. Execute your script.....