$value = $_SESSION[$key] = str_pad(mt_rand(0, 9999), 4, '0', STR_PAD_LEFT); session_write_close(); // 生成验证码图 header('Content-type: image/png'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache -Control: no-store, no-cache , must-revalidate"); header("Cache -Control: post-check=0, pre-check=0", false); header("Pragma: no-cache "); $im = imagecreate(47, 17); $color = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $color); $color = imagecolorallocate($im, 255, 0, 0); imagestring($im, 5, 5, 1, $value, $color); imagepng($im); imagedestroy($im); } else { // 返回验证码号 session_start(); $value = isset($_SESSION[$key]) ? $_SESSION[$key] : null; unset($_SESSION[$key]); session_write_close(); return $authcode === $value; } } } /** * 执行(execute) */ front::stub() and front::main();