亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP生成圖片驗(yàn)證碼、點(diǎn)擊切換實(shí)例

 更新時(shí)間:2014年06月25日 09:19:12   投稿:junjie  
這篇文章主要介紹了PHP生成圖片驗(yàn)證碼實(shí)例,同時(shí)介紹了點(diǎn)擊切換(看不清?換一張)效果實(shí)現(xiàn)方法,需要的朋友可以參考下

這里來(lái)看下效果:

現(xiàn)在讓我們來(lái)看下 PHP 代碼

復(fù)制代碼 代碼如下:

<?php
 
session_start();
function random($len) {
    $srcstr = "1a2s3d4f5g6hj8k9qwertyupzxcvbnm";
    mt_srand();
    $strs = "";
    for ($i = 0; $i < $len; $i++) {
        $strs .= $srcstr[mt_rand(0, 30)];
    }
    return $strs;
}
 
//隨機(jī)生成的字符串
$str = random(4);
 
//驗(yàn)證碼圖片的寬度
$width  = 50;     
 
//驗(yàn)證碼圖片的高度
$height = 25;    
 
//聲明需要?jiǎng)?chuàng)建的圖層的圖片格式
@ header("Content-Type:image/png");
 
//創(chuàng)建一個(gè)圖層
$im = imagecreate($width, $height);
 
//背景色
$back = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
 
//模糊點(diǎn)顏色
$pix  = imagecolorallocate($im, 187, 230, 247);
 
//字體色
$font = imagecolorallocate($im, 41, 163, 238);
 
//繪模糊作用的點(diǎn)
mt_srand();
for ($i = 0; $i < 1000; $i++) {
    imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pix);
}
 
//輸出字符
imagestring($im, 5, 7, 5, $str, $font);
 
//輸出矩形
imagerectangle($im, 0, 0, $width -1, $height -1, $font);
 
//輸出圖片
imagepng($im);
 
imagedestroy($im);
 
$str = md5($str);
 
//選擇 cookie
//SetCookie("verification", $str, time() + 7200, "/");
 
//選擇 Session
$_SESSION["verification"] = $str;
?>

接下來(lái)只要在頁(yè)面中調(diào)用就可以了:

復(fù)制代碼 代碼如下:

<img id="checkpic" onclick="changing();" src='/images/checkcode.php' />

如果想實(shí)現(xiàn) "看不清?換一張" 效果,添加如下 JS 到頁(yè)面中

復(fù)制代碼 代碼如下:

function changing(){
    document.getElementById('checkpic').src="/images/checkcode.php?"+Math.random();
}

相關(guān)文章

最新評(píng)論