Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Generowanie tokena
sajborg
post
Post #1





Grupa: Zarejestrowani
Postów: 271
Pomógł: 0
Dołączył: 20.08.2003
Skąd: Szczecinek

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


Witam mam taki sobie kodzik na token

token.php
  1. <?php
  2. $img["width"] = 240;
  3. $img["height"] = 86;
  4. $img["text"] = $_GET['t'];
  5. $img["file"] = @imagecreatefromjpeg ("token_background.jpg");
  6.  
  7. $font["angle"] = rand(-5,5);
  8. $font["files"] = array ( "stilltim.ttf", "dipedm.ttf", "zoinkfat.ttf" );
  9. $font["rand"] = array_rand ( $font["files"] );
  10. $font["file"] = $font["files"][$font["rand"]];
  11.  
  12. $token = imagecreatetruecolor ( $img["width"], $img["height"] );
  13.  
  14. $color["white"] = imagecolorallocate ( $token, 0,0,);
  15.  
  16. imagecopy ( $token, $img["file"], 0, 0, 0, 0, $img["width"], $img["height"] );
  17.  
  18. $box = imagettfbbox ( 24, $font["angle"], $font["file"], $img["text"] );
  19.  
  20. $x = (int) ( ( $img["width"] - abs ( max ( $box[2], $box[4] ) ) ) / 2);
  21. $y = (int) ( ( $img["height"] + abs ( max ( $box[5], $box[7] ) ) ) / 2);
  22.  
  23. imagecolorallocate ( $token, 0, 0, 0 );
  24. imagettftext ( $token, 24, $font["angle"], $x, $y, $color["white"], $font["file"], $img["text"] );
  25.  
  26. header ( 'Content-type: image/gif' );
  27. imagegif ( $token );
  28. imagedestroy( $token );
  29. ?>


Teraz w pliku z formem mam

register.php
  1. <?php
  2. $banned = array("#0#si", "#O#si");
  3. $tekst = preg_replace( $banned, "X", strtoupper ( substr ( md5 ( uniqid ( rand(), true ) ), 0, 8 ) ) );
  4.  
  5. echo '<img src="token.php?t='.$tekst.'" alt="">';
  6.  
  7. ?>


Ale takie rozwiazanie latwo ominac bo kod tokena bedzie w kodzie a to roboty moga wychwycic. A Z kolei w pliku token.php nie moge generowac kodu bo bedzie mi on potrzebny w pliku form.php wiec jak mam to rozwiazac questionmark.gif?


--------------------
Warsztat: gPHPEdit | Linux 2.6.17-11-generic (Ubuntu)
Sprzęt: Noteook BenQ A33E
___________________________________________________
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 20.08.2025 - 15:58