3v4l.org

run code in 300+ PHP versions simultaneously
<?php session_start(); // Zufaelligen captchastring erstellen function random_string() { $chars = 'ABCDEFGHKLMNPQRSTUVWXYZ23456789'; $string = ''; $i = 1; $max = 5; while ($i <= $max) { $char = substr($chars,rand(0,strlen($chars)-1),1); $string .= $char; $i++; } return $string; } // captcha code ausgeben function get_captcha() { $old = time()-(60*20); if (empty($_SESSION['captcha'])) return null; if ($_SESSION['captcha']['date'] < $old) return null; return $_SESSION['captcha']['code']; } // captcha erstellen function make_captcha() { unset($_SESSION['captcha']); $string = random_string(); $width = 200; $height = 75; $font = 'captcha.ttf'; $one = imagecreate($width,$height); $two = imagecreate($width,$height); $bgone = imagecolorallocate($one,0,0,0); $txtone = imagecolorallocate($one,255,255,255); $bgtwo = imagecolorallocate($two,255,255,255); $txttwo = imagecolorallocate($two, 0, 0, 0); imagettftext($one,32,0,10,$height-20,$txtone,$font,$string); $y = 0; while ($y < $height) { $x = 0; while ($x < $width) { $r = rand(1,2); if ($r == 1) { $dot = imagecolorat($one,$x,$y); if ($dot == 0) { imagesetpixel($two,$x,$y,$txttwo); imagesetpixel($one,$x,$y,$txtone); } else { imagesetpixel($one,$x,$y,$bgone); imagesetpixel($two,$x,$y,$txttwo); } } $x++; } $y++; } imagecolortransparent($one,$txtone); imagecolortransparent($two,$bgtwo); $old_content = ob_get_contents(); ob_clean(); imagepng($one); $imgone = ob_get_contents(); ob_clean(); imagepng($two); $imgtwo = ob_get_contents(); ob_clean(); echo $old_content; $_SESSION['captcha'] = array('code'=>$string,'date'=>time()); $audiostring = implode('+.', str_split($string)); return '<div style="background-image:url(data:image/png;base64,'. base64_encode($imgone).');background-repeat:no-repeat;background-color:#FFFFFF;width:'.($width).';"><img src="data:image/png;base64,'. base64_encode($imgtwo).'" border="0" /></div>' . '<audio controls autoplay style="width:200px;"><source src="data:audio/mpeg;base64,' . base64_encode(file_get_contents('http://translate.google.com/translate_tts?tl=de&q=' . $audiostring)) . '" type="audio/mpeg"></audio>'; } die(make_captcha());

preferences:
53.66 ms | 402 KiB | 5 Q