Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Prosty generator captcha + sesje
lDoran
post
Post #1





Grupa: Zarejestrowani
Postów: 172
Pomógł: 13
Dołączył: 15.11.2009

Ostrzeżenie: (0%)
-----


Witam wymodziłem prosty generator kodu captcha:
  1. <?php
  2. /* START GENERATOR CAPTCHA */
  3. function captchaGenerator() {
  4. $sAplhaNum = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789';
  5. $_SESSION['captcha'] = substr(str_shuffle($sAplhaNum), 0, 5);
  6. $sRand2 = substr(str_shuffle($sAplhaNum), 0, 5);
  7.  
  8. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  9. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  10. header("Cache-Control: no-store, no-cache, must-revalidate");
  11. header("Cache-Control: post-check=0, pre-check=0", false);
  12. header("Pragma: no-cache");
  13. header('Content-type: image/png');
  14.  
  15. $image = imagecreatetruecolor(60, 30);
  16. $white = imagecolorallocate($image, 255, 255, 255);
  17. imagefilledrectangle($image, 0, 0, 120, 40, $white);
  18. $greylight = imagecolorallocate($image, 199, 199, 199);
  19. $black = imagecolorallocate($image, 0, 0, 0);
  20. imagestring ($image, 5, 8, 4, $sRand2, $greylight);
  21. imagestring ($image, 5, 12, 5, $_SESSION['captcha'], $black);
  22. imagepng($image);
  23. imagedestroy($image);
  24. }
  25.  
  26. captchaGenerator();
  27. /* END GENERATOR CAPTCHA */
  28. ?>

Jednak przy pierwszym wyświetleniu na stronie zmienna sesyjna nie istnieje, a obrazek jest wyświetlany. Każde kolejne wyświetlenie zmienna sesyjna pokazuje n-1 kod obrazka gdzie n to aktualny kod obrazka. W czym tkwi problem?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.09.2025 - 23:21