Using Captcha Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PHPMan
Forum Newbie
Posts: 13
Joined: Thu Nov 18, 2004 8:47 am

Using Captcha Images

Post by PHPMan »

Hey guys,
I got this code here, and right now the way it works is, when you hit
'Check It' (the button) it makes sure you have entered the proper characters to correspond with the image...Im wondering what I'd have to add to this script so that when you click -> 'Check it'
that it takes you to another page (which Ill specify in a URL)
I think I have to edit where it says:
<form action="<?echo $_SERVER["PHP_SELF"]?>" method=get>
to method post correct? then, hmm just not sure where to specify the URL, that it will take you too...any tips?

Code: Select all

<?php
<?php
/**
* The form has posted.
* Check the code which the user has entered!
*/
if(isset($_GET["code"]))
{
    require "class.img_validator.php";
    $img = new img_validator();
    $img->checks_word($_GET["code"]);
    echo "<HR>";
}
?>
<body onload="document.forms[0].code.focus();">
<form action="<?echo $_SERVER["PHP_SELF"]?>" method=get>
<img src="img.php?words=true" border=0><BR><BR>
Type the image code/word: <input type=text name=code> <input type=submit value="Check it!"><BR>Obs: It must be identical as the image (case sensitive)</form>
</body>
</html>
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I always recommend using POST when using forms... and to specify where you want your form is by changing the action... for example

<form action="validate.php" method="POST">
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Sidenote on Phenoms response: if you're writing valid xhtml then you'll need to specify attribute values in lowercase letters. So to specify a forms method as post you'd do:

Code: Select all

<form method="post">
as opposed to:

Code: Select all

<form method="POST">
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

ooooooooooooopsy
PHPMan
Forum Newbie
Posts: 13
Joined: Thu Nov 18, 2004 8:47 am

Thanks

Post by PHPMan »

hehe, thanks guys I really appreciate it :)
Ill post again here if for some reason I can't get it to work out

Regards,
PHPMan
Forum Newbie
Posts: 13
Joined: Thu Nov 18, 2004 8:47 am

One thing

Post by PHPMan »

Am, I using
<form action="validate.php" method="post">
Or
<form method=post>
Like nigma suggested?

On the page validate.php
Ill make it so that it says 'Your account is now Active,bla,bla'
Im just not sure which to use
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I was just providing an example, as was Phenom.

The <form> tag is used to define a form. Like most html tags the <form> tag has both optional and required attributes. The only required attribute is the action attribute which defines the url where the data in the form will be sent. The method attribute is an optional attribute which can be set to either "get" or "post".

Look at w3cschool's page on the form tag for more information.

So, say you have two pages (form.php and process.php). form.php will contain a form and process.php will be used to process the data that was entered in the form. Here's how things might look on both pages:

Code: Select all

&lt;form method="post" action="process.php"&gt;
&lt;input type="text" name="myname" /&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;

Code: Select all

&lt;?php
echo "Hello " . $_POST&#1111;'myname'];
?&gt;
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

By the way, this post doesn't belong in the PHP Theory and Design forum. Instead it belongs in the PHP - Code forum (which is where i've moved it).

Please read our guide on posting before posting again.
PHPMan
Forum Newbie
Posts: 13
Joined: Thu Nov 18, 2004 8:47 am

Captcha

Post by PHPMan »

Alrighty,
So basically, I have my form.php
basically what I need to do now is my process.php
Im having the biggest problem with this:

I have a html form already made. [Full of registration info]
At the end of the form is (supposed to be,lol) a Captcha image.
So it looks like the code Ive included, but what Im trying to figure out is:
how to get it to where when the submit button is clicked, that it checks the
catpcha image, makes sure the strings are equal, and on the next page
(validate.php) it will either say: Validation Complete, or Validation Invalid.
Now, I added <form action="validate.php' method=post>
Now, I have to make php file called validate, that has on the top of it
<include form.php> (then put all the info such as, echo validation is complete, or validation failed.

Code: Select all

<?php
<?php

session_start();
?>
<html>
<head>
<title>Validator Example</title>
</head>
<body>
<font face=verdana size=2>
<?php
/**
* The form has posted.
* Check the code which the user has entered!
*/
if(isset($_GET["code"]))
{
    require "class.img_validator.php";
    $img = new img_validator();
    $img->checks_word($_GET["code"]);
    echo "<HR>";
}
?>
<body onload="document.forms[0].code.focus();">
<form action="validate.php method=post>
<img src="img/img.php" border=0><BR><BR>
Type the image code/word: <input type=text name=code> <input type=submit value="Check it!"><BR>Obs: It must be identical as the image (case sensitive)</form>
</body>
</html>

?>
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I don't think I understand your question but it seems to me like you might benefit from reading this tutorial on working with forms in html.
Post Reply