首頁 > 後端開發 > php教程 > PHP认证码兑现

PHP认证码兑现

WBOY
發布: 2016-06-13 13:09:31
原創
1019 人瀏覽過

PHP认证码实现

include '../lib/function.php';

if (!isset($_SESSION)) {
??? session_start();
??? header('Cache-control:private');
}
$width = 65;
$height = 20;
$image = imagecreate($width, $height);
$bg_color = imagecolorallocate($image, 0x33, 0x66, 0xFF);
imagefilledrectangle($image, 0, 0, $width, $height, $bg_color);
$text = random_text(5);
$font = 5;
$x = imagesx($image) / 2 - strlen($text) * imagefontwidth($font) / 2;
$y = imagesy($image) / 2 - imagefontheight($font) / 2;
$fg_color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
imagestring($image, $font, $x, $y, $text, $fg_color);
$_SESSION['captcha'] = $text;
header('Content-type:image/png');
imagepng($image);
imagedestroy($image);
?>

?

function random_text($count, $rm_similar = false)
{
??? $chars = array_flip(array_merge(range(0, 9), range('A', 'Z')));
??? if ($rm_similar) {
??????? unset($chars[0], $chars[1], $chars[2], $chars[5], $chars[8], $chars['B'], $chars['I'],
??????????? $chars['O'], $chars['Q'], $chars['S'], $chars['U'], $chars['V'], $chars['Z']);
??? }
??? for ($i = 0, $text = ''; $i ??????? $text .= array_rand($chars);
??? }
??? return $text;
}
?>

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板