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 (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
niko
post
Post #2





Grupa: Zarejestrowani
Postów: 109
Pomógł: 0
Dołączył: 2.06.2005

Ostrzeżenie: (30%)
XX---


Spoko poprawiłem literówkę na preg_replace i wywala mi coś takiego :


Warning: preg_replace(): Empty regular expression in /home/XXX/public/domena-pl/token.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at /home/XXX/public/domena-pl/token.php:18) in /home/XXX/public/domena-pl/token.php on line 41
GIF87ađU€üţü,đUţ„Ź&copy;ËíŁś´Ú‹ł Ľű†âH–ć‰&brvbar;ę&para;îđL×öŤçş'ďţ …˝ˇńˆL&‹&brvbar;ó M1ŁÔŞ9˝j&middot;ÜY&para; ‹Aß&plusmn;ů|-Ł×ě% Źcßňş]§ľë÷§<˙ŘáH¨7Xˆw˜Čˆ&para;ŘöI&copy;5Y‰u™É&copy;´Ů :ôJę3ZŠzsš łÚ &raquo;ňKk2[‹C—Ë[sŰËű Ś+<L[l ‹śĚşĚŚęüL- J]ÍyŤŤ&copy;˝MŮí Î8NŽh~N˜&reg;ČŢÎ÷o¸;o,o_‡źŻXĎěď&plusmn;€Ź,¨ě Âf BkčpĈÖ&RĚfń"&middot;WŚżqě(î#Čr"G˘+ir”îV˛Śçň%=™ivÚgó ÎśMvňtół’Ď F†%󨣤JÍmjŠ)TIR§vyjÖ&not;64xý 6&not;Ř&plusmn;dË.(;

czyli cosik jeszcze nie łapie (IMG:http://forum.php.pl/style_emoticons/default/sad.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: 18.09.2025 - 14:18