• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

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:
		#recaptcha_image img 
{ 
        width: 150px; 
} 	

Open in new window


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>&nbsp;<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>

Open in new window

0
Razzmataz73
Asked:
Razzmataz73
  • 4
  • 4
1 Solution
 
Ray PaseurCommented:
0
 
Razzmataz73Author Commented:
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?
0
 
Ray PaseurCommented:
Of course!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Razzmataz73Author Commented:
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:
<!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>&nbsp;<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>

Open in new window

0
 
Ray PaseurCommented:
You would want to store the CAPTCHA code in the session array.  IIRC the article discusses that part.

See http://laprbass.com/RAY_temp_razzmataz73.php

<?php // RAY_temp_razzmataz.php
error_reporting(E_ALL);

// START THE SESSION ON EVERY PAGE, NO EXCEPTIONS
session_start();

// IF THERE IS A POST-METHOD REQUEST
if (!empty($_POST))
{
    if (strtoupper($_POST['captcha']) == strtoupper($_SESSION['captcha']))
    {
        echo 'YOU GOT IT RIGHT';
        /* RUN THE REST OF THE SCRIPT HERE */
    }
    else
    {
        echo 'YOU GOT IT WRONG';
        /* RUN THE ERROR HANDLER FOR CAPTCHA HERE */
    }
}

// SET THE CAPTCHA VALUE IN THE SESSION
$captcha = random_string();
$_SESSION['captcha'] = $captcha;

// CREATE THE FORM
$form = <<<EOD
<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>
Please Enter $captcha<br>
<input type="text" name="captcha" id="validate" />
<br>
<input type='submit' value='Submit' name='submit' align='right'>
</font>
</form>
EOD;

echo $form;


// 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;
}

Open in new window

HTH, ~Ray
0
 
Razzmataz73Author Commented:
It worked PERFECTLY!!!

Thank YOU!!
0
 
Razzmataz73Author Commented:
Worked exactly as he said it would!
Great Support!
0
 
Ray PaseurCommented:
Thanks for the points and thanks for using EE! ~Ray
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now