2014-05-14, 12:57 AM
(This post was last modified: 2014-05-21, 04:52 PM by SouthernPride.)
I have a php script that shows image of cats and dogs and you have to select all cats. It pulls the images from two different folders. I can get it to work by modding newthread.php, newreply.php and the post_captcha template.
I would love to have this as a plugin for MyBB but I am not smart enough to do it. To out smart the spambots all I have to do is change the images every so often.
I would love to have this as a plugin for MyBB but I am not smart enough to do it. To out smart the spambots all I have to do is change the images every so often.
<?php
define('CAPTCHA_NR',5);
define('CAPTCHA_CAT',1);
define('CAPTCHA_DOG',0);
define('CAPTCHA_IMG_NR',20);
session_start();
//if we have an image request serve the image
if ( isset( $_GET['captcha'] ) )
{
header('Content-Type: image/jpeg');
if ( $_SESSION['_captcha'][ $_GET['captcha'] ] == CAPTCHA_DOG )
{
exit( readfile( dirname(__FILE__) . '/dogs/' . rand( 1, CAPTCHA_IMG_NR) . '.jpg' ) );
} else
{
exit( readfile( dirname(__FILE__) . '/cats/' . rand( 1, CAPTCHA_IMG_NR) . '.jpg' ) );
}
}
//check if the cats were checked
if ( isset( $_POST['_captcha'] ) )
{
$captcha_ok = true;
//check if the user checked the cats
for ( $i = 1; $i <= CAPTCHA_NR; $i++ )
{
//if the checkboxes are not set assume that they are dogs
if ( ! isset( $_POST['_captcha'][$i] ) ) $_POST['_captcha'][$i] = 0;
//do we have a match ?
if ( $_SESSION['_captcha'][$i] != $_POST['_captcha'][$i] )
{
$captcha_ok = false;
break;
//wrong guess
}
}
}
//generate images permutation
//make them all dogs
for ( $i = 1; $i <= CAPTCHA_NR; $i++ )
{
$_SESSION['_captcha'][$i] = CAPTCHA_DOG;
}
//add at least one cat, but no more than half of the images
for ( $i = 1; $i <= (CAPTCHA_NR / 2); $i++ )
{
$_SESSION['_captcha'][rand(1, CAPTCHA_NR) ] = CAPTCHA_CAT;
}
?>
<html>
<head>
<style>
#captcha
{
width:400px;
margin:10px;
}
#captcha div
{
float:left;
margin:5px;
background:#ccc;
height:auto;
text-align:center;
width:50px;
}
#captcha input
{
width:1em;
display:block;
}
.captcha_message
{
color:red;
font-size:1.2em;
margin:10px;
}
</style>
</head>
<body>
</p>
<p><b class="captcha_message">
<?php
if ( isset( $captcha_ok ) )
{
if ( $captcha_ok == true )
{
echo 'You are a human !';
}
else
{
echo 'Not a kittie lover or bad spam robot !!!';
}
}
?>
</b></p>
<p><font color="#FF0000"><h4> Human Test. Please Select All Cats From The Images Below</h4></font></p>
<div id="captcha">
<?php for ( $i = 1; $i <= CAPTCHA_NR; $i++ ):?>
<div>
<input type="checkbox" name="_captcha[<?php echo $i;?>]" value="1">
<img src="catdogcaptcha.php?captcha=<?php echo $i?>&time=<?php echo time();?>">
</div>
<?php endfor ?>
</div>
</p>
</body>
</html>