Jump to content

Recommended Posts

Back into php after about 6 months, trying to re learn alot, started making a quick program that just creates a random math problem, addition or multiplication with numbers 1-9 to verify wether it's a bot or not. So far I've got it generating random math problems with those variables as seen here:

http://74.70.230.229/verification/verify.php

 

Now I know I can make it so they must enter the answer and have it verify it, except for the part where I'm trying to figure out the answer to the question myself! In order to display the images for the numbers, I made the variable $keyone equal to images/filename.gif. Now I'm trying to convert it back to the number and then do the math, with horrible failure, wondering if anyone could give any advice.

 

Before you look at the code, I know it is EXTREMELY inefficient and awful, just something to get me back into the programming mindset.

 

Code:

<?php

function randkey($length)
{
  $pattern = "123456789";
  for($i=0;$i<$length;$i++)
  {
   if(isset($key))
     $key .= $pattern{rand(0,9)};
   else
     $key = $pattern{rand(0,};
  }
  return $key;
}

$keyone = randkey(1);
$keytwo = randkey(1);

// determine if its + or *
$func_id = rand(0,1);
if ($func_id==0)
{
	$function = "+";
	$function = "images/plus.gif";
} else {
	$function = "*";
	$function = "images/multiply.gif";
}
// end of + or *

// convert the number into the number image
if ($keyone=="1")
{	
	$keyone = "images/one.gif";
} elseif ($keyone=="2")
{	$keyone = "images/two.gif";
} elseif ($keyone=="3")
{	$keyone = "images/three.gif";
} elseif ($keyone=="4")
{	$keyone = "images/four.gif";
} elseif ($keyone=="5")
{ 	$keyone = "images/five.gif";
} elseif ($keyone=="6")
{	$keyone = "images/six.gif";
} elseif ($keyone=="7")
{	$keyone = "images/seven.gif";
} elseif ($keyone=="8")
{	$keyone = "images/eight.gif";
} elseif ($keyone=="9")
{ 	$keyone = "images/nine.gif";
}

if ($keytwo=="1")
{	
	$keytwo = "images/one.gif";
} elseif ($keytwo=="2")
{	$keytwo = "images/two.gif";
} elseif ($keytwo=="3")
{	$keytwo = "images/three.gif";
} elseif ($keytwo=="4")
{	$keytwo = "images/four.gif";
} elseif ($keytwo=="5")
{ 	$keytwo = "images/five.gif";
} elseif ($keytwo=="6")
{	$keytwo = "images/six.gif";
} elseif ($keytwo=="7")
{	$keytwo = "images/seven.gif";
} elseif ($keytwo=="8")
{	$keytwo = "images/eight.gif";
} elseif ($keytwo=="9")
{ 	$keytwo = "images/nine.gif";
}
// end of number to number image conversion

// display in image the problem - x (+or*) x
echo "<img src=\"$keyone\"> <img src=\"$function\"> <img src=\"$keytwo\"> <br />";
	// end of display

?>

Link to comment
https://forums.phpfreaks.com/topic/48879-bot-spammer-verification-system/
Share on other sites

You can store the generated values in a session, like this:

 

session_start(); # At the very top of the script
$_SESSION['keyone'] = $keyone;
$_SESSION['keytwo'] = $keytwo;
$_SESSION['funcid'] = $funcid;

 

Then there's no need to convert back.

 

You need to clear this data once the test has been completed, to make sure the same data can't be re-used by a bot.

 

It also somewhat defeats the purpose to let the bot know the names of the images you are using :)  I guess you will fix that later.

I'd thought along the lines of actually utilising your variable values KeyOne and KeyTwo.

 

It's basic, but may get your thought process going.

 

Strip the left of the values until you reach the "."

Convert the word to the numeric value.

Combine to re-create the math problem

Workout and validate

 

EmperorJazzy

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.