Razzmataz73
asked on
Need a small php captcha
Hello,
I need help to resize (but keep readable) recaptcha down to 200px width or another captcha that is small and uses PHP and/or javascript.
Would prefer it to be numbers if possible.
I have implemented recaptcha successfully but it is too large to be in our sidebar where the form is.
I have used the code:
Which works great for resizing the image but the rest of the recaptcha is still too big for my working area.
The testpage I am working on is:
http://visailing.com/Shopping-Cart/Captcha-Test.php
The captcha shouldn't be bigger then the email text box so it can fit onto the sidebar when called.
Thanks in advance for your direction.
Here is the complete code of my test form.
I need help to resize (but keep readable) recaptcha down to 200px width or another captcha that is small and uses PHP and/or javascript.
Would prefer it to be numbers if possible.
I have implemented recaptcha successfully but it is too large to be in our sidebar where the form is.
I have used the code:
#recaptcha_image img
{
width: 150px;
}
Which works great for resizing the image but the rest of the recaptcha is still too big for my working area.
The testpage I am working on is:
http://visailing.com/Shopping-Cart/Captcha-Test.php
The captcha shouldn't be bigger then the email text box so it can fit onto the sidebar when called.
Thanks in advance for your direction.
Here is the complete code of my test form.
<?php
define( API_PUBLIC_KEY, '6Lc9sOESAAAAAPeBaO8hi48A8CEc60B9dzhGJ8Sp' );
define( API_PRIVATE_KEY, '6Lc9sOESAAAAAILGaphhS7fh-dxEUTh7kfbLMY7Z' );
require_once('recaptchalib.php');
$validated = false;
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Captch Test</title>
<style type="text/css">
#recaptcha_error_box {
width:30%;
border:medium groove #A00;
background-color:#FF9;
padding:1em;
color:#900;
font-weight:bold;
font-size:80%;
}
.table_success {
background-color:#009;
border:thin dashed #999;
padding:2em;
font-size:90%;
color:#FFF;
}
#recaptcha_image img {
width: 150px;
}
</style>
<script>
var RecaptchaOptions = {
theme : 'blackglass',
tabindex : 2
};
</script>
</head>
<body>
<?
if( $_POST['validate'] === 'yes' ) {
$response = recaptcha_check_answer( API_PRIVATE_KEY,
$_SERVER['REMOTE_ADDR'],
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
if( ! $response->is_valid ) {
echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>';
}
else {
$validated = true;
$emailbody = "The following yachts and information were submitted through the <b>My Yacht List</b>:<br>";
$emailbody .= "<b><br>Email Address: ".$email."</b>";
if($clientname =="") {} else { $emailbody .= "<br>Client Name: ". $clientname;}
$date= date("m/d/y h:i:s");
include_once('/var/www/visailing.com/_mail/class.phpmailer.php');
$mail = new PHPMailer();
$body = $emailbody;
$mail->From = "myyachtlist@visailing.com";
$mail->FromName = "My Yacht List";
$mail->Subject = "My Yacht List Request Availability: ".$date ;
$mail->MsgHTML($emailbody);
$mail->AddAddress("heather@visailing.com");
if(!$mail->Send()) { echo 'Failed to send mail';
} else {
;}
$requestmessage = "<br> <br><font color='red'>Your request has been sent</font><br>";
header("Location: http://www.visailing.com/caribbean-sailing/yacht-availability-thank-you.php?requesttype=myyachtlist");
}
}
?>
<?php if( ! $validated ) { ?>
<form method="post">
<font color='007698' size='2'>
Full Name:<br>
<input type="text" id="clientname" name="clientname" ><br>
Email :<br>
<input type="text" id="email" name="email"><br>
<?php echo recaptcha_get_html(API_PUBLIC_KEY); ?>
<input type="hidden" name="validate" value="yes" />
<input type='submit' value='Submit' name='submit' align='right'>
</font>
</form>
<?php } ?>
</body>
</html>
ASKER
Wow!
That looks amazing!
I am leaving now but will try one of those options later tonight.
Can I post to this thread if I have questions?
That looks amazing!
I am leaving now but will try one of those options later tonight.
Can I post to this thread if I have questions?
Of course!
ASKER
This is GREAT!
I am going to go with your code for:
An Image-based CAPTCHA Test
I have it working but how do I make it so if they enter in the correct text it goes to my code:
//If Captcha is valid then do this
I have it running on this test page:
http://www.visailing.com/Shopping-Cart/Captcha-Test.php
And here is the code:
I am going to go with your code for:
An Image-based CAPTCHA Test
I have it working but how do I make it so if they enter in the correct text it goes to my code:
//If Captcha is valid then do this
I have it running on this test page:
http://www.visailing.com/Shopping-Cart/Captcha-Test.php
And here is the code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Captch Test</title>
</head>
<body>
<?
//If Captcha is valid then do this
if( $_POST['validate'] === 'yes' ) {
if( ! $response->is_valid ) {
echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>';
}
else {
$validated = true;
$emailbody = "The following yachts and information were submitted through the <b>My Yacht List</b>:<br>";
$emailbody .= "<b><br>Email Address: ".$email."</b>";
if($clientname =="") {} else { $emailbody .= "<br>Client Name: ". $clientname;}
$date= date("m/d/y h:i:s");
include_once('/var/www/visailing.com/_mail/class.phpmailer.php');
$mail = new PHPMailer();
$body = $emailbody;
$mail->From = "myyachtlist@visailing.com";
$mail->FromName = "My Yacht List";
$mail->Subject = "My Yacht List Request Availability: ".$date ;
$mail->MsgHTML($emailbody);
$mail->AddAddress("heather@visailing.com");
if(!$mail->Send()) { echo 'Failed to send mail';
} else {
;}
$requestmessage = "<br> <br><font color='red'>Your request has been sent</font><br>";
header("Location: http://www.visailing.com/caribbean-sailing/yacht-availability-thank-you.php?requesttype=myyachtlist");
}
}
?>
<?php if( ! $validated ) { ?>
<form method="post">
<font color='007698' size='2'>
Full Name:<br>
<input type="text" id="clientname" name="clientname" ><br>
Email :<br>
<input type="text" id="email" name="email"><br>
<?
error_reporting(E_ALL);
// FUNCTION TO MAKE A RANDOM STRING
function random_string($length=5)
{
// POSSIBLE PERMUATIONS http://www.mathwords.com/p/permutation_formula.htm
// pow($length,strlen($alpha)); = 32*31*30*29*28 = 24,165,120 IF LENGTH IS 5
// 1...5...10...15...20...25...30......
$alpha = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$array = str_split($alpha);
$randy = NULL;
while(strlen($randy) < $length)
{
// CHOOSE A LETTER AT RANDOM, USE IT AND REMOVE IT
$point = mt_rand(0, count($array)-1);
$randy .= $array[$point];
unset($array[$point]);
$array = array_values($array);
}
return $randy;
}
// TEST THE FUNCTION
echo "Please enter the following captcha:<br><b>".random_string();
?>
</b><br>
<input type="text" name="validate" id="validate" />
<br>
<input type='submit' value='Submit' name='submit' align='right'>
</font>
</form>
<?php } ?>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked PERFECTLY!!!
Thank YOU!!
Thank YOU!!
ASKER
Worked exactly as he said it would!
Great Support!
Great Support!
Thanks for the points and thanks for using EE! ~Ray
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_9849-Making-CAPTCHA-Friendlier-with-PHP-Image-Manipulation.html
HTH, ~Ray