Home > OS >  How can I require a captcha to load a page?
How can I require a captcha to load a page?

Time:09-05

I would like a simple PHP captcha script that would require the user so solve a captcha to load the website page. Preferably a captcha that doesn't need a third party such as reCAPTCHA, all done locally.

CodePudding user response:

You can look at the example here:

https://code.tutsplus.com/tutorials/build-your-own-captcha-and-contact-form-in-php--net-5362

I would also recommend using the timer on your page since bots are becoming better at passing capchas. By timer, I mean time between landing on the page and creating an account/submitting the form.

CodePudding user response:

This is VERY simple. Usually no one is going to put any effort to bypass the captcha unless you have something worth while aka $$$$.

Just post an image with a question. Like What is 345 x 100,000 957?
The have an small form with a <input> for them to answer.

You could have any number of images and answers.

$captcha[] = array($answer,$image);
$captcha[] = array($answer,$image);
$captcha[] = array($answer,$image);

Then

 $cnt = count($captcha) - 1;
 $rec = rand(0,$cnt);
 $answer= captcha[$rec][0];
 $image = captcha[$rec][1];
 echo '<img scr="$image"/>';
 echo '<form action="$url" method="post">';
 echo '<input type = "text" name="answer" /></form>';
 $id = intval(str_replace('.','',$_SERVER['REMOTE_ADDR']));
 file_put_contents("$id.txt",$answer);

The in the $url page:

 $id = intval(str_replace('.','',$_SERVER['REMOTE_ADDR']));
 $answer = intval(file_get_contents("$id.txt"));
 unlink("$id.txt");
 $pass = false;
 if $answer == intval($_POST['answer']){$pass = true;}
  • Related