Does anyone now how to make the invalid captcha warning come up as a pop up and not a new screen as it currently does. I have tried replacing this code but i cannot get it to work:
}
else {
echo "Invalid Captcha String.";
}
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes I do but it is not trivial. I will try to put together some directions but again, I have to warn you it requires quite a bit of code changes. Are you up for it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here are the steps required:
1.) Separate the "CaptchaSecurityImages.php" file into 2 parts ("CaptchaSecurityCode.php" and "CaptchaSecurityImage.php").
2.) Rename the "form.html" file into "form.php".
3.) Add a "validateCaptcha()" function to the "form.php" file.
4.) Add a function call to "validateCaptcha()" in the "form.php" file.
5.) Add the "CaptchaSecurityCode.php" as an include statement at the top of the "form.php" file.
6.) Change the previous instance of "CaptchaSecurityImages.php" to the new "CaptchaSecurityImage.php" in the "form.php" file.
This sounds simple enough but if you get it wrong the "form.php" file may not even be displayed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That was not intended to be instructions, just an outline of steps required. As long as you are not intimidated by the scope of the work I can begin to put together some instructions. Is this what you want to do?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
<?php
session_start();
/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 23/11/06
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
class CaptchaSecurityImage {
var $font = 'monofont.ttf';
function CaptchaSecurityImage($width='120',$height='40',$characters='6') {
$code = $_SESSION;
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox)/2;
$y = ($height - $textbox)/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
imagejpeg($image);
imagedestroy($image);
}
}
$width = isset($_GET) ? $_GET : '120';
$height = isset($_GET) ? $_GET : '40';
$characters = isset($_GET) ? $_GET : '6';
header('Content-Type: image/jpeg');
$captcha = new CaptchaSecurityImage($width,$height,$characters);
?>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
<?php
session_start();
/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 23/11/06
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
$characters = isset($_GET) ? $_GET : '6';
$newcode=generateCode($characters);
$_SESSION=$newcode;
?>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Find these comment lines in the form.php file
<!- expand/collapse function ->
<!- validate ->
They occur together and just before these lines.
<SCRIPT type=text/javascript>
<!-
function validateField(fieldId, fieldBoxId, fieldType, required)
Put the following code between the two comment lines.
Type the following: <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>For security purposes, please type the letters in the image.</span></a><BR><img src="CaptchaSecurityImages.php" />
Change "CaptchaSecurityImages.php" to "CaptchaSecurityImage.php".
Type the following: <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>For security purposes, please type the letters in the image.</span></a><BR><img src="CaptchaSecurityImage.php" />
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Once you have completed all these steps, here is what should happen.
1.) Test it but leaving the captcha value blank. The box should turn pink like any other required field when you leave it blank. You will get a popup that says "Please correct the errors. Fields marked with an asterisk (*) are required".
I now see that this is not quite accurate so you should modify this alert comment in step 4 to read something like "The Captcha field is required. Please correct this error.".
2.) Test it by putting in the captcha value with an error. You will get a popup that says "Invalid Captcha String: {captcha value entered}".
3.) Test it by putting in the exact captcha value. The form will continue without any popup related to the capcha value.
Let me know if this works as I say it should. I don't think I have left anything out.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok I think I followed these instructions carefully. Here is an error message that I am now getting displayed:
Warning: session_start() : Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\test_site\enrol.php:10) in C:\xampp\htdocs\test_site\CaptchaSecurityCode.php on line 2
Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test_site\enrol.php:10) in C:\xampp\htdocs\test_site\CaptchaSecurityCode.php on line 2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure what you are doing but it is related to this file "enrol.php".
The "CaptchaSecurityCode.php" file is meant to be inserted into the very top (line 2 right after "<?php") of your form file.
The error starts on line 10 of your "enrol.php".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Does anyone now how to make the invalid captcha warning come up as a pop up and not a new screen as it currently does. I have tried replacing this code but i cannot get it to work:
Thanks
Yes I do but it is not trivial. I will try to put together some directions but again, I have to warn you it requires quite a bit of code changes. Are you up for it?
Here are the steps required:
1.) Separate the "CaptchaSecurityImages.php" file into 2 parts ("CaptchaSecurityCode.php" and "CaptchaSecurityImage.php").
2.) Rename the "form.html" file into "form.php".
3.) Add a "validateCaptcha()" function to the "form.php" file.
4.) Add a function call to "validateCaptcha()" in the "form.php" file.
5.) Add the "CaptchaSecurityCode.php" as an include statement at the top of the "form.php" file.
6.) Change the previous instance of "CaptchaSecurityImages.php" to the new "CaptchaSecurityImage.php" in the "form.php" file.
This sounds simple enough but if you get it wrong the "form.php" file may not even be displayed.
Thanks for the instructions, I shall give it a go.
Regards
Julian
That was not intended to be instructions, just an outline of steps required. As long as you are not intimidated by the scope of the work I can begin to put together some instructions. Is this what you want to do?
It is yes, so I would be gratefull if you could provide some instructions.
Regards
Julian
Create this file "CaptchaSecurityImage.php".
<?php
session_start();
/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 23/11/06
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
class CaptchaSecurityImage {
var $font = 'monofont.ttf';
function CaptchaSecurityImage($width='120',$height='40',$characters='6') {
$code = $_SESSION;
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox)/2;
$y = ($height - $textbox)/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
imagejpeg($image);
imagedestroy($image);
}
}
$width = isset($_GET) ? $_GET : '120';
$height = isset($_GET) ? $_GET : '40';
$characters = isset($_GET) ? $_GET : '6';
header('Content-Type: image/jpeg');
$captcha = new CaptchaSecurityImage($width,$height,$characters);
?>
Create this file "CaptchaSecurityCode.php".
<?php
session_start();
/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 23/11/06
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
$characters = isset($_GET) ? $_GET : '6';
$newcode=generateCode($characters);
$_SESSION=$newcode;
?>
Rename your "form.html" to "form.php". Add this to the very top of the file.
<?php
include('CaptchaSecurityCode.php');
?>
Find these comment lines in the form.php file
<!- expand/collapse function ->
<!- validate ->
They occur together and just before these lines.
<SCRIPT type=text/javascript>
<!-
function validateField(fieldId, fieldBoxId, fieldType, required)
Put the following code between the two comment lines.
<?php
print '
<SCRIPT type=text/javascript>
<!-
function validateCaptcha(fieldId, fieldBoxId, fieldType, required)
{
fieldBox = document.getElementById(fieldBoxId);
fieldObj = document.getElementById(fieldId);
sess_val="'.$_SESSION.'";
if(required == 1 && fieldObj.value == "")
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
alert("Please correct the errors. Fields marked with an asterisk (*) are required");
return false;
}
else
{
if(fieldObj.value == sess_val) {
return true;
}
else {
alert("Invalid Captcha String: " + fieldObj.value);
return false;
}
}
}
//->
</SCRIPT>';
?>
Find the following line in the form.php file.
Type the following: <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>For security purposes, please type the letters in the image.</span></a><BR><img src="CaptchaSecurityImages.php" />
Change "CaptchaSecurityImages.php" to "CaptchaSecurityImage.php".
Type the following: <a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>For security purposes, please type the letters in the image.</span></a><BR><img src="CaptchaSecurityImage.php" />
Find the following lines in the form.php file.
if(retVal == false)
{
alert('Please correct the errors. Fields marked with an asterisk (*) are required');
return false;
}
Right after these lines, insert the following code.
if (validateCaptcha('security_code','captchaForm','textarea',1) == false)
retVal=false;
Once you have completed all these steps, here is what should happen.
1.) Test it but leaving the captcha value blank. The box should turn pink like any other required field when you leave it blank. You will get a popup that says "Please correct the errors. Fields marked with an asterisk (*) are required".
I now see that this is not quite accurate so you should modify this alert comment in step 4 to read something like "The Captcha field is required. Please correct this error.".
2.) Test it by putting in the captcha value with an error. You will get a popup that says "Invalid Captcha String: {captcha value entered}".
3.) Test it by putting in the exact captcha value. The form will continue without any popup related to the capcha value.
Let me know if this works as I say it should. I don't think I have left anything out.
Thanks for the detailed instructions. I'll let you know how I get on.
Regards.
Ok I think I followed these instructions carefully. Here is an error message that I am now getting displayed:
Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test_site\enrol.php:10) in C:\xampp\htdocs\test_site\CaptchaSecurityCode.php on line 2
I'm not sure what you are doing but it is related to this file "enrol.php".
The "CaptchaSecurityCode.php" file is meant to be inserted into the very top (line 2 right after "<?php") of your form file.
The error starts on line 10 of your "enrol.php".