Проблемка такая скрипт генерит рандом числа и помещает в сессию для последующего вывода на картинку с использованием библиотеки gd2, но при первом заходе генериться постоянно одно и тоже число не могу найти ошибку.... код самой картинки
| Код | <?php session_start(); $_SESSION["formsafe"];
function mt() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); }
Header("Content-type: image/png"); $font = 'epsilon-font.ttf'; $image = ImageCreate(100, 30); ImageFill($image, 0, 0, $black); $black = ImageColorAllocate($image, 255, 255, 255); $yellow = ImageColorAllocate($image, 0, 0, 0);
$firstwhite=imagecolorallocate($image, 190, 190, 190); $randomcolor[1]=imagecolorallocate($image,rand(0,200),rand(0,128),rand(0,150)); $randomcolor[2]=imagecolorallocate($image,rand(0,128),rand(0,200),rand(0,128)); $randomcolor[3]=imagecolorallocate($image,rand(0,128),rand(0,150),rand(0,128)); $randomcolor[4]=imagecolorallocate($image,rand(0,180),rand(0,128),rand(0,150));
for ($i=0;$i<=100;$i+=5) imageline($image,$i,0,$i,29,$firstwhite); for ($i=0;$i<=29;$i+=5) imageline($image,0,$i,100,$i,$firstwhite);
imagettftext($image, 17, 10, 10+rand(-5,5), 5+rand(20,15), $randomcolor[1], $font,substr($_SESSION["formsafe"],0,1)); imagettftext($image, 17, 10, 25+rand(-5,5), 5+rand(20,15), $randomcolor[2], $font,substr($_SESSION["formsafe"],1,1)); imagettftext($image, 17, 10, 50+rand(-5,5), 5+rand(20,15), $randomcolor[3], $font,substr($_SESSION["formsafe"],2,1)); imagettftext($image, 17, 10, 70+rand(-5,5), 5+rand(20,10), $randomcolor[4], $font,substr($_SESSION["formsafe"],3,1)); imagepng($image); imagedestroy($image); //echo $text; ?>
|
Код который генерит число для сессии
| Код | <? session_start(); $_SESSION["formsafe"]; if (intval($_SESSION["formsafe"])<1000) { srand(doubleval(microtime())); $_SESSION["formsafe"]=rand(1000,9999); }
?>
//Тут форма которая отправляет запрос... на картинку <? if ($_SERVER["REQUEST_METHOD"]=="POST") {
$itext=0; if ($_POST["secretcode"]!=$_SESSION["formsafe"] || intval($_POST["secretcode"])==0) $itext=1;
if ($itext==0) { $_SESSION["formsafe"]=rand(1000,9999); print "введенное слово :".htmlspecialchars(StripSlashes($_POST["text"])); exit; }
if ($itext==1) $_SESSION["formsafe"]=rand(1000,9999); print "Код с картинки неверный"; }
?>
| |