I'm getting fed up of getting automated posts from a form which I have on my site, almost always containing just junk, and by looking at the server logs they do not appear to be sent via a browser.
Is there a way of introducing a check stage, where the person has to retype a series of numbers from an image, to verify that it is not an automated post, and is completed by a human, before posting the form?
I use 'formail' and the form functions by;
<form action="/cgi-bin/formposter.pl" method="post">
but I have been told that I should seek a server-side solution as that would be the most effective.
Any ideas please?
bokeh
04-01-2006, 03:48 PM
Consider adding a captcha to your form. Check my signature for more info.
pauldreed
04-01-2006, 04:48 PM
Consider adding a captcha to your form. Check my signature for more info.
This is excellent!
I think that this is exactly what I am looking for but not sure how to use it.
I need to somehow integrate this into my HTML form so that it displays within the form, and if the correct digits are entered, then it posts the form <form action="/cgi-bin/form2email.pl" method="post"> but if incorrect, instead of clearing the contents of the form data, it refreshes the image to a different one so the person can retry.
Can the php code be integrated into a HTML doc, or does the entire form need to be written in php?
This is the form (http://www.safeinsouthyorks.co.uk/form.html)
Sheldon
04-01-2006, 06:17 PM
Can the php code be integrated into a HTML doc, or does the entire form need to be written in php?
The last post from Sheldon shows, I beleive how to call up a php module from a HTML form, but I am wanting this to be integrated to within the form.
For example; the user completes the form, and in order to submit it, must copy the letters/numbers contained within the image to an inputbox. If correct, then the form contents pass to an emailing script, and if wrong, then the image is refreshed (without losing the data within the form) to give the person another opportunity.
I am sorry, but I am not very experienced in php, and cannot find another way of resolving this issue, except through php, so any help you can give would be appreciated.
bokeh
04-02-2006, 09:38 AM
The problem is this is the php forum and your handler is a perl script. If you are considering switching to php post your html form and perl script to see if it can easily be converted.
pauldreed
04-02-2006, 02:44 PM
The problem is this is the php forum and your handler is a perl script. If you are considering switching to php post your html form and perl script to see if it can easily be converted.
I am redesigning the form, so I will do it with a php handler instead.
As you have suggested, I have attached both the form and php script (a basic cutdown version with just 3 fields, no images etc).
<HTML><HEAD><TITLE>Example Form</TITLE></HEAD>
<BODY>
<font face='arial' size=2><b>All fields marked with a * are required:<br>
<form enctype='multipart/form-data' action='process.php' method='post'>
<table border=1 bordercolor='#000000'><tr><tr>
<table width='50%' border=0>
<tr><td bgcolor='#C0C0C0'> Name<font color='#ff0000'>*</font></td>
<td bgcolor='#C0C0C0'>
<input type=text name='Name'></td></tr>
<tr><td bgcolor='#CCCCCC'> Email Address</td>
<td bgcolor='#CCCCCC'>
<input type=email name='EmailAddress'></td></tr>
<tr><td bgcolor='#C0C0C0'> Comments</td>
<td bgcolor='#C0C0C0'>
<textarea name='Comments' rows=20 cols=20></textarea></td></tr>
</table>
</td></tr></table>
<input type='submit' value='Submit Form'> <input type=reset value='Clear Form'></form>
<br><br><br>
</BODY></HTML>
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','EmailAddress');
pt_register('POST','Comments');
$Comments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $Comments);if($Name=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EmailAddress)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email Address: ".$EmailAddress."
Comments: ".$Comments."
";
$message = stripslashes($message);
mail("example@email.com","Form Submitted by your website",$message,"From: Name of your site");
?>
<!-- This is the content of the Thank you page, be careful while changing it -->
<h2>Thank you!</h2>
<table width=50%>
<tr><td>Name: </td><td> <?php echo $Name; ?> </td></tr>
<tr><td>Email Address: </td><td> <?php echo $EmailAddress; ?> </td></tr>
<tr><td>Comments: </td><td> <?php echo $Comments; ?> </td></tr>
</table>
<!-- Do not change anything below this line -->
<?php
}
?>
I have generated the form and php code via PhpFormGenerator.
bokeh
04-02-2006, 03:25 PM
So what is in this file: global.inc.php Also if you want to make the form sticky, the form and the handler will need to be the same php script.
You really should get your hands dirty and write the PHP yourself rather than some GUI program writing it for you. It's a terrible mess. A tables layout and the php code is pretty out of date too.
pauldreed
04-02-2006, 03:41 PM
So what is in this file: global.inc.php Also if you want to make the form sticky, the form and the handler will need to be the same php script.
You really should get your hands dirty and write the PHP yourself rather than some GUI program writing it for you. It's a terrible mess. A tables layout and the php code is pretty out of date too.
Sorry, the global.inc.php is;
<?php
function pt_register()
{
$num_args = func_num_args();
$vars = array();
if ($num_args >= 2) {
$method = strtoupper(func_get_arg(0));
if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
}
$varname = "HTTP_{$method}_VARS";
global ${$varname};
for ($i = 1; $i < $num_args; $i++) {
$parameter = func_get_arg($i);
if (isset(${$varname}[$parameter])) {
global $$parameter;
$$parameter = ${$varname}[$parameter];
}
}
} else {
die('You must specify at least two arguments');
}
}
?>
I was not too concerned about the layout of the form, because I can easily change that to CSS when I redo it, The form and code as posted works as I have pulled it from my server, but unfortunatly I do not have the skills to write the php code from scratch. I'm OK HTML, CSS, etc but you can't imagine how complex and scary this code looks to me!
I thought initially that it would not be too difficult to combine Captcha with a form, but after reading the various posts it may be beyond my capabilities, but thanks for your advice.
Sheldon
04-02-2006, 04:18 PM
That is so poor!
Delete both, stick with your first form, the form is not the problem.
integrating CAPTCA is not hard
try writing your own mail script using http://php.net/mail with bokehs CAPTCHA script
pauldreed
04-02-2006, 04:49 PM
That is so poor!
Delete both, stick with your first form, the form is not the problem.
integrating CAPTCA is not hard
try writing your own mail script using http://php.net/mail with bokehs CAPTCHA script
Sorry Sheldon, I visited that site earlier and it made it as clear as mud to me.
Without pointing me back to php.net is there a absolute basic mail script which would serve as a guide to start from.
I know you guy's are trying to help me by pointing me in the right direction, but php is just like learning a different language, and I don't know where to start.
I initially posted here because I thought that this would have been explored before, and that I would be able to simply amend existing code.
This does not appear to be the case, so I will have to find a solution within my capabilities, but thanks for the guidance.
bokeh
04-02-2006, 06:42 PM
If you can wait until tomorrow I will post something.
bokeh
04-03-2006, 07:47 AM
The following should give you a good starting point. It is self contained so does not require any additional files. Fill in the email address of the recipient on line 4. No other changes should be necessary. I have separated the PHP and HTML sections as much as practically possible. The HTML is valid and does not use tables. <?php
# fill this in with the address to which the email will be sent
$recipient = '';
function error()
{
if(empty($_POST['name']))
{
return 'ERROR: The name field is empty.';
}
if(preg_match('/[^a-zA-Z ]/', $_POST['name']))
{
return 'ERROR: The name field contains invalid characters.';
}
if(empty($_POST['email']))
{
return 'ERROR: The email field is empty.';
}
if(!eregi('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $_POST['email']))
{
return 'ERROR: The email field contains invalid syntax.';
}
if(empty($_POST['comments']))
{
return 'ERROR: The comments field is empty.';
}
if(!captcha_validate())
{
return 'ERROR: Incorrect security code entered.';
}
return false;
}
Absolutly brilliant! this is really good, thank you for spending time and helping me.
I can use this as a template to develop it into a full reporting form, with the corporate branding, and yes, I will keep coding in CSS. This is the first time I have ventured into php - except through using php-fusion (which is a brilliant CMS) and your coding is a fantastic way in for a new starter.
The Captcha image is really small, is that because it no size is specified, or is it related to the system font size?
Thanks Again
bokeh
04-03-2006, 04:07 PM
The Captcha image is really small, is that because it no size is specified, or is it related to the system font size?Size 5 is the largest built in font and because I wanted to do it all with one file this is the only possible way... But that image is 80 x 20... if in the <img> element you specified different dimmensions you could stretch the image. For example change the <img> to:<img src="<?php echo $src ?>" width="120" height="30" alt="captcha">The resulting image might look a bit pixelated and aliased but at least it would be a bit bigger.
The only other method is using an external truetype font as does the captcha script in my signature. Size is no problem then because ttf text is scaleable.
pauldreed
04-03-2006, 04:17 PM
Size 5 is the largest built in font and because I wanted to do it all with one file this is the only possible way... But that image is 80 x 20... if in the <img> element you specified different dimmensions you could stretch the image. For example change the <img> to:<img src="<?php echo $src ?>" width="120" height="30" alt="captcha">The resulting image might look a bit pixelated and aliased but at least it would be a bit bigger.
The only other method is using an external truetype font as does the captcha script in my signature. Size is no problem then because ttf text is scaleable.
I tried that but the image shrinks immediatly back to the original size, I have tried to add aditional code to use ttf fonts by following the Captcha script code but not managed it yet!
I will persevere!
The rest of the code is not as daunting, I have already added more fields, field size & positioning.
pauldreed
04-03-2006, 04:30 PM
Bokeh
Eventually managed it!
I have pasted the code from the Captcha script, into the 'new' form, and now it works with ttf & background image! I simply forgot to add the path sttement;
define('CAPTCHA_PATH', $_SERVER['DOCUMENT_ROOT'].'/captcha/');
See, I'm learning!
Thanks
bokeh
04-03-2006, 04:34 PM
Can I see the resulting code?
pauldreed
04-03-2006, 04:38 PM
Can I see the resulting code?
It still needs a lot of extra work - formatting, a lot more fields ect, but this works great. I have a directory on my site /captcha which contains the ttf files.
<?php
# fill this in with the address to which the email will be sent
$recipient = 'my.email.co.uk';
function error()
{
if(empty($_POST['name']))
{
return 'ERROR: The name field is empty.';
}
if(preg_match('/[^a-zA-Z ]/', $_POST['name']))
{
return 'ERROR: The name field contains invalid characters.';
}
if(empty($_POST['email']))
{
return 'ERROR: The email field is empty.';
}
if(!eregi('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $_POST['email']))
{
return 'ERROR: The email field contains invalid syntax.';
}
if(empty($_POST['comments']))
{
return 'ERROR: The comments field is empty.';
}
if(!captcha_validate())
{
return 'ERROR: Incorrect security code entered.';
}
return false;
}
Bokeh, Im not so lucky I cany get the captchga image to show?That's weird because I copied your code and it worked for me. GD.
pauldreed
04-04-2006, 02:25 PM
Sheldon
The code in #19 above looks like this (http://www.firstimageweb.co.uk/paul2.php) using a couple of ttf files in a /captcha directory.
pauldreed
04-05-2006, 02:57 PM
The original 'Captcha' script (http://bokehman.com/captcha_verification) from Bokeh had a audio link for the image, I have tried all afternoon to transfer that code across to this form but failed miserably, If anyone has more luck, please post it, thanks.
webdeveloper.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.