PDA

View Full Version : Captcha how to???


Paws
04-07-2007, 05:49 PM
I have a few captcha scripts and have them working great, but how do I make it work in my current contact and registration forms?

I can post my captcha scripts that do work on my machine but can't seem to get them to work on my current pages.

Is there someone who can give me a tip or two.

davidj
04-08-2007, 10:29 AM
whats not working ?

more info please

Paws
04-08-2007, 10:35 AM
The problem is that I have the captcha working now with my form, but it is blank on the server that I am hosting and I think I need to get a file called captcha.jpg to get it work.

Will post if there are any other, q's.

davidj
04-08-2007, 10:37 AM
The problem is that I have the captcha working now with my form, but it is blank on the server


so its working locally but not on the live machine

Paws
04-08-2007, 10:43 AM
Yes, but I think I need an image called captcha.jpg on the server, but I don't need it on my machine, which is odd.

Paws
04-08-2007, 11:08 AM
Ok Got it work but the problem I have is that the error dsiplays at the top of the page and not next to the textbox, any ideas on how to do that?

Paws
04-08-2007, 11:11 AM
Here is the code that I am using:
This verifies the captcha:

<?
session_start();
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
echo '<strong>Incorrect verification code.</strong><br>';
} else {
// add form data processing code here
// echo '<strong>Verification successful.</strong><br>';
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

?>

BUt I would like the error to display next to the textbox, any ideas how?

davidj
04-08-2007, 11:18 AM
assign the error code to a variable and echo the variable in the page where you want it display'd

Paws
04-08-2007, 11:22 AM
Using this:

or die(mysql_error()

My version would be this:

or die(mysql_error(#error_number)

Is this right?

davidj
04-08-2007, 11:35 AM
built in error handling is good for debugging but its much nicer to create your own

where you have...

echo '<strong>Incorrect verification code.</strong><br>';

just do this...

$error = '<strong>Incorrect verification code.</strong><br>';

then you can echo the $error var anywhere you like on the page

Paws
04-08-2007, 11:44 AM
Thanks

I guess it takes the observer to solve the most easiest issues.

8)
Thanks
8)

davidj
04-08-2007, 11:52 AM
TOP TIP:

if you building a robust, scalable application then its best to keep all your error codes together

create a page called errors.php

then add...


<?php

define('A123', 'error: this is an error message');
define('A124', 'error: this is another error message');
define('A125', 'error: this is one too');

?>


add an include to the page you want to call the errors

include("errors.php");

then to call them just set an $error var like this...

$error = A123;

then just echo $error

Paws
04-08-2007, 11:57 AM
Will do thank you.

Paws
04-08-2007, 12:01 PM
On top of that I need to now add a check to to see if the user actually clicked submit or not;

Will do it with a hidden field, I don't enjoy naming my submit buttons.

Thanks again.