Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Token
moto0095
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Witam znalazłem ostatnio i przerobiłem pewien token.
Tylko nie wiem jak dodać do niego jakieś plamki, kreski itp. w tle.
oto kod:
  1. <?php
  2. session_start(); //rozpoczecie sesji
  3. header ('Content-type: image/png'); //wyslanie naglowkow do przegladarki
  4. header ('Expires: '.gmdate ('r', 0));
  5. header ('Last-Modified: '.gmdate ('r'));
  6. header ('Cache-Control: no-store, no-cache, must-revalidate');
  7. header ('Pragma: no-cache');
  8.  
  9. $chars = array(1,2,3,4,5,6,7,8,9,'e','r','t','u','i','p','a','g','h','j','z','c','b','n','m'); //Lista znakow
  10.  
  11. for($i = 0; $i < 6; $i++) //Losowanie znakow
  12. {
  13. $text .= $chars[array_rand($chars)];
  14. }
  15.  
  16. $_SESSION['token'] = $text;
  17. //Tworzenie obrazka
  18. $image = imagecreatetruecolor(100, 32);
  19. $background = imagecolorallocate($image, 0, 0, 0);
  20.  
  21. imagefill($image, 0, 0, $background);
  22.  
  23. $textcolor = imagecolorallocate($image, 255, 255, 255);
  24. imagestring($image, 10, 25, 8, $text, $textcolor);
  25.  
  26. imagepng($image);
  27.  
  28. imagedestroy ($Image);
  29. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
moto0095
post
Post #2





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Wiem że to ta funkcja tylko nie wiem jak ją podpiąć.

Okey poradziłem sobie jakoś.
Oto kod może się komuś przyda (IMG:style_emoticons/default/smile.gif)
  1. <?
  2. $pool = '0123456789abcdefghijklmnopqrstuvwxyz';
  3. $img_width = 120;
  4. $img_height = 30;
  5.  
  6. $str = '';
  7. for ($i = 0; $i < 7; $i++){
  8. $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
  9. }
  10.  
  11. $string = $str;
  12. $_SESSION['captcha'] = $string;
  13.  
  14. $im = imagecreate($img_width, $img_height);
  15.  
  16. $color1 = rand(0,150);
  17. $color2 = rand(0,150);
  18. $color3 = rand(0,150);
  19.  
  20. $colorbg1 = rand(0,150);
  21. $colorbg2 = rand(0,150);
  22. $colorbg3 = rand(0,150);
  23.  
  24. $colorfont1 = rand(200,255);
  25. $colorfont2 = rand(200,255);
  26. $colorfont3 = rand(200,255);
  27.  
  28. $bg_color = imagecolorallocate($im,$colorbg1,$colorbg2,$colorbg3);
  29. $font_color = imagecolorallocate($im,$colorfont1,$colorfont2,$colorfont3);
  30. $grid_color = imagecolorallocate($im,$color1,$color2,$color3);
  31. $border_color = imagecolorallocate ($im, 174, 174, 174);
  32.  
  33. imagefill($im,1,1,$bg_color);
  34.  
  35.  
  36. ImageLine($im,90,0,90,30,$grid_color); //1
  37. ImageLine($im,10,0,10,30,$grid_color); //2
  38. ImageLine($im,20,0,20,30,$grid_color); //1
  39. ImageLine($im,30,0,30,30,$grid_color); //1
  40. ImageLine($im,40,0,40,30,$grid_color); //1
  41. ImageLine($im,50,0,50,30,$grid_color); //1
  42. ImageLine($im,60,0,60,30,$grid_color); //1
  43. ImageLine($im,70,0,70,30,$grid_color); //1
  44. ImageLine($im,80,0,80,30,$grid_color); //1
  45. ImageLine($im,90,0,90,30,$grid_color); //2
  46. ImageLine($im,100,0,100,30,$grid_color); //1
  47. ImageLine($im,110,0,110,30,$grid_color); //1
  48. ImageLine($im,120,0,120,30,$grid_color); //1
  49.  
  50. ImageLine($im,0,0,-80,30,$grid_color); //1
  51. ImageLine($im,10,0,-70,30,$grid_color); //1
  52. ImageLine($im,20,0,-60,30,$grid_color); //1
  53. ImageLine($im,30,0,-50,30,$grid_color); //1
  54. ImageLine($im,40,0,-40,30,$grid_color); //1
  55. ImageLine($im,50,0,-30,30,$grid_color); //1
  56. ImageLine($im,60,0,-20,30,$grid_color); //1
  57. ImageLine($im,70,0,-10,30,$grid_color); //1
  58. ImageLine($im,80,0,0,30,$grid_color); //1
  59. ImageLine($im,90,0,10,30,$grid_color); //1
  60. ImageLine($im,100,0,20,30,$grid_color); //1
  61. ImageLine($im,110,0,30,30,$grid_color); //1
  62. ImageLine($im,120,0,40,30,$grid_color); //1
  63. ImageLine($im,130,0,50,30,$grid_color); //1
  64. ImageLine($im,140,0,60,30,$grid_color); //1
  65. ImageLine($im,150,0,70,30,$grid_color); //1
  66. ImageLine($im,160,0,80,30,$grid_color); //1
  67. ImageLine($im,170,0,90,30,$grid_color); //1
  68. ImageLine($im,180,0,100,30,$grid_color); //1
  69. ImageLine($im,190,0,110,30,$grid_color); //1
  70. ImageLine($im,200,0,120,30,$grid_color); //1
  71.  
  72. ImageLine($im,0,5,120,5,$grid_color); //1
  73. ImageLine($im,0,10,120,10,$grid_color); //1
  74. ImageLine($im,0,15,120,15,$grid_color); //1
  75. ImageLine($im,0,20,120,20,$grid_color); //1
  76. ImageLine($im,0,25,120,25,$grid_color); //1
  77.  
  78.  
  79. $x = rand(7, $img_width/(7/2));
  80.  
  81. imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);
  82.  
  83. for($a=0; $a < 7; $a++){
  84.  
  85. imagestring($im, 5, $x, rand(8 , $img_height/7), substr($string, $a, 1), $font_color);
  86. $x += (5*2); #odstęp
  87.  
  88. }
  89.  
  90. header("Content-type: image/gif");
  91. imagegif($im);
  92. imagedestroy($im);
  93.  
  94. ?>


Aby nie zaczynać nowego tematu to zapytam się tutaj.
Jak zrobić odświeżanie tego tokena po kliknięciu na przycisk np: "Inny", ale bez przeładowania strony (wiem że można to zrobić w ajaxie tylko ja nie znam go w ogóle ) (IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/questionmark.gif)
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.10.2025 - 13:24