How can I organize a display of captcha before the first entrance to the site? (code please)

Closed due to the fact that the essence of the question is not clear by the participants aleksandr barakin , 0xdb , freim , Alex , andreymal 4 May at 16:25 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Alternatively, you can make a captcha validation and write the result of processing in cookie / session, and redirect to authorization where this result will be checked. But for the first time I see captcha doing this .. - MoloF
  • It is necessary in practice, in theory, it is clear - Roman Grishin
  • one
    Well, maybe you can open up the question in more detail and put at least the code of what you have? It helps to solve the problem / question, but not to do everything from scratch .. - MoloF
  • What kind of code? There is a simple default site with several pages in PHP. Everything. Code pages does not matter. - Roman Grishin
  • four
    Possible duplicate question: Show captcha before entering - u_mulder

1 answer 1

Google before writing here http://lifeexample.ru/php-primeryi-skriptov/kapcha-na-php.html

And here is an example from the site:

НуТно Π·Π°ΠΏΠΈΠ»ΠΈΡ‚ΡŒ 5 Ρ„Π°ΠΉΠ»ΠΎΠ²: index.php – скрипт выводящий Π½Π°ΡˆΡƒ ΠΊΠ°ΠΏΡ‡Ρƒ Π½Π° PHP; validator.php – скрипт ΠΏΡ€ΠΎΠ²Π΅Ρ€ΡΡŽΡ‰ΠΈΠΉ сходство с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΎΠΉ; capcha.php – скрипт Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΡƒΡŽΡ‰ΠΈΠΉ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ; comic.ttf – ΡˆΡ€ΠΈΡ„Ρ‚ тСкста; bg_capcha.png – Ρ„ΠΎΠ½ ΠΏΠΎΠ΄ тСкстом. 

index.php

 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΊΠΎΠ΄ с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ: <br/> <img style="border: 1px solid gray; background: url('bg_capcha.png');" src = "captcha.php" width="120" height="40"/> <br/> <form action="validator.php" method="POST"> <input type="text" name="capcha" /> <input type="submit" name="send" value="ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΈΡ‚ΡŒ"/> </form> 

capcha.php

  $letters = 'ABCDEFGKIJKLMNOPQRSTUVWXYZ'; // Π°Π»Ρ„Π°Π²ΠΈΡ‚ $caplen = 6; //Π΄Π»ΠΈΠ½Π° тСкста $width = 120; $height = 40; //ΡˆΠΈΡ€ΠΈΠ½Π° ΠΈ высота ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ $font = 'comic.ttf';//ΡˆΡ€ΠΈΡ„Ρ‚ тСкста $fontsize = 14;// Ρ€Π°Π·ΠΌΠ΅Ρ€ тСкста header('Content-type: image/png'); //Ρ‚ΠΈΠΏ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΠΎΠ³ΠΎ содСрТимого (ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π² Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π΅ PNG) $im = imagecreatetruecolor($width, $height); //создаёт Π½ΠΎΠ²ΠΎΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ imagesavealpha($im, true); //устанавливаСт ΠΏΡ€ΠΎΠ·Ρ€Π°Ρ‡Π½ΠΎΡΡ‚ΡŒ изобраТСния $bg = imagecolorallocatealpha($im, 0, 0, 0, 127); //ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Ρ†Π²Π΅Ρ‚Π° для изобраТСния imagefill($im, 0, 0, $bg); //выполняСт Π·Π°Π»ΠΈΠ²ΠΊΡƒ Ρ†Π²Π΅Ρ‚ΠΎΠΌ putenv( 'GDFONTPATH=' . realpath('.') ); //провСряСт ΠΏΡƒΡ‚ΡŒ Π΄ΠΎ Ρ„Π°ΠΉΠ»Π° со ΡˆΡ€ΠΈΡ„Ρ‚Π°ΠΌΠΈ $captcha = '';//обнуляСм тСкст for ($i = 0; $i < $caplen; $i++) { $captcha .= $letters[ rand(0, strlen($letters)-1) ]; // дописываСм случайный символ ΠΈΠ· Π°Π»Ρ„Π°Π²ΠΈΠ»Π° $x = ($width - 20) / $caplen * $i + 10;//растояниС ΠΌΠ΅ΠΆΠ΄Ρƒ символами $x = rand($x, $x+4);//случайноС смСщСниС $y = $height - ( ($height - $fontsize) / 2 ); // ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° Y $curcolor = imagecolorallocate( $im, rand(0, 100), rand(0, 100), rand(0, 100) );//Ρ†Π²Π΅Ρ‚ для Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Π±ΡƒΠΊΠ²Ρ‹ $angle = rand(-25, 25);//случайный ΡƒΠ³ΠΎΠ» Π½Π°ΠΊΠ»ΠΎΠ½Π° imagettftext($im, $fontsize, $angle, $x, $y, $curcolor, $font, $captcha[$i]); //Π²Ρ‹Π²ΠΎΠ΄ тСкста } // ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ сСссию для сохранСния сгСнСрированного тСкста session_start(); $_SESSION['capcha'] = $captcha; imagepng($im); //Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ imagedestroy($im);//ΠΎΡ‚Ρ‡ΠΈΡ‰Π°Π΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ 

validator.php

 session_start(); if($_POST['capcha'] != $_SESSION['capcha']) echo "ВСкст с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ Π²Π²Π΅Π΄Π΅Π½ Π½Π΅ Π²Π΅Ρ€Π½ΠΎ!"; else echo "Π£Ρ€Π° тСкст совпал!";