-
隨即中文驗(yàn)證碼
查看全部 -
動(dòng)態(tài)校驗(yàn)
查看全部 -
實(shí)現(xiàn)字母和數(shù)字混合驗(yàn)證碼
for 循環(huán),字典由字母與數(shù)字組成。
查看全部 -
imagesetpixel畫一個(gè)隨機(jī)的像素。
imagesetpixel(resource $iamge,int $x,int $y,int color)
imageline(resource $image,int $x1,int $y1,int $x2,int $y2,int $color)畫一條線端。
查看全部 -
實(shí)現(xiàn)數(shù)字驗(yàn)證碼
在底圖上顯示隨機(jī)數(shù)字
for循環(huán)
變色驗(yàn)證碼
隨機(jī)的點(diǎn)——干擾元素
實(shí)現(xiàn)數(shù)字驗(yàn)證碼
在底圖上顯示隨機(jī)數(shù)字
for循環(huán)
變色驗(yàn)證碼
隨機(jī)的點(diǎn)——干擾元素
查看全部 -
搭建php運(yùn)行環(huán)境,搜索XAMPP下載安裝。
打開xampp文件地址,在站點(diǎn)文件夾htdots下,新建一個(gè)php文件。輸入簡(jiǎn)單的內(nèi)容判斷是否能正常運(yùn)行。
檢查php是否支持GD,輸入<?php? phpinfo():查看輸出即可。
實(shí)現(xiàn)簡(jiǎn)單的驗(yàn)證碼
在htdots站點(diǎn)下,打開project目錄創(chuàng)建php文件;
生成底圖:圖像繪制imagecreatetruecolor(int $width,int $height) 。
header方法輸出圖片的類型;
imagecreatetruecolor(int $width,int $height) 。默認(rèn)返回黑色底圖。
imagecolorallocate($image,int red,int green,int blue)為圖像分配顏色。
9.imagefill($image,int x,int y,int color)區(qū)域填充,在iamge圖像的坐標(biāo)x,y(圖像左上角為(0,0)處用color顏色執(zhí)行區(qū)域填充;
查看全部 -
<?php
//phpinfo();
//生成驗(yàn)證碼底圖
$image=@imagecreatetruecolor(100, 30);//返回一個(gè)黑色的圖片
$text_color = imagecolorallocate($image, 255, 255, 255);
// $bgcolor=imagecolorallocate($image,255,255,255);
// imagefill($image,0,0,$bgcolor);
// header('content-type: image/png');
// imagedestroy($image);
imagefill($image,0,0,$text_color);//區(qū)域填充
for($i=0;$i<4;$i++)//利用for循環(huán)生成四位數(shù)字
{
? ? $fontsize=6;//字體大小
? ? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//設(shè)置數(shù)字的顏色
? ? $fontcontent=rand(0,9);
? ? //注意事項(xiàng):控制好字體的大小和分布,避免字體重疊或顯示不全
? ? $x=($i*100/4)+rand(5,10);
? ? $y=rand(5,10);
? ? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
for($i=0;$i<200;$i++)
{
? ? $pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
? ? //生成隨機(jī)點(diǎn)干擾顏色(較淺),給惡意破解程序增加難度
? ? imagesetpixel($image,rand(1,99),rand(1,99),$pointcolor);
}
header ('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
查看全部 -
<?php
//phpinfo();
//生成驗(yàn)證碼底圖
$image=@imagecreatetruecolor(120, 20);//返回一個(gè)黑色的圖片
$text_color = imagecolorallocate($image, 255, 255, 255);
// $bgcolor=imagecolorallocate($image,255,255,255);
// imagefill($image,0,0,$bgcolor);
// header('content-type: image/png');
// imagedestroy($image);
imagefill($image,0,0,$text_color);//區(qū)域填充
header ('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
查看全部 -
文字無(wú)法顯示
查看全部 -
輸出一個(gè)隨機(jī)數(shù)。 有的瀏覽器會(huì)對(duì)相同url做cache,若cache了,這個(gè)請(qǐng)求就達(dá)不到我們效果。所以加個(gè)隨機(jī)數(shù),避免被瀏覽器cache。
有的瀏覽器不夠聰明,會(huì)cache歷史數(shù)據(jù),導(dǎo)致刷新失敗。 加隨機(jī)數(shù)是這個(gè)作用。
查看全部 -
http://idcbgp.cn/qadetail/25142
查看全部 -
https://bbs.csdn.net/topics/390932524
為什么驗(yàn)證碼 必須要開啟 ob_clean 才可以顯示?
這表示你的程序前面有輸出,<?php?前有空格、空行、文件有BOM頭
查看全部 -
啦啦啦啦查看全部
-
SESSION 存儲(chǔ)驗(yàn)證信息
查看全部 -
實(shí)現(xiàn)簡(jiǎn)單的驗(yàn)證碼
查看全部 -
captcha.php
<?php
session_start();
//畫布
$image = imagecreatetruecolor(100, 30);
$bgcolor = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bgcolor);
//隨機(jī)數(shù)字
/*
for ($i=0; $i < 4; $i++) {
$fontsize = 10;
$fontcolor = imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
$fontcontent = rand(0,9);
$x = ($i*100/4) + rand(5,10);
$y = rand(5,10);
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
}
*/
$captch_code = '';
//數(shù)字字母組合
for ($i=0; $i <4; $i++) {
$fontsize = 8;
$fontcolor = imagecolorallocate($image, rand(0,80), rand(0,80), rand(0,80));
$data = 'abcdefghijkmnpqrstuvwxy3456789';
$fontcontent = substr($data, rand(0,strlen($data)),1);
$captch_code .= $fontcontent;
$x = ($i*100/4) + rand(5,10);
$y = rand(5,10);
imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
}
$_SESSION['authcode'] = $captch_code;
//將captch_code保存到session的authcode中
//干擾點(diǎn)
for ($i=0; $i <300 ; $i++) {
$pointcolor = imagecolorallocate($image, rand(80,220), rand(80,220), rand(80,220));
imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor);
}
//干擾線
for ($i=0; $i <3 ; $i++) {
$linecolor = imagecolorallocate($image, rand(120,220), rand(120,220), rand(120,220));
imageline($image, rand(1,99), rand(1,29), rand(1,99), rand(1,29), $linecolor);
# code...
}
header('content-type: image/png');
imagepng( $image );
//end
imagedestroy( $image );
?>
查看全部 -
form.php
<?php
header('content-type:text/html;charset=utf-8');
if(isset($_REQUEST['authcode'])){
session_start();
if(strtolower($_REQUEST['authcode'])==$_SESSION['authcode']){
echo '<font color="#0000CC">輸入正確</font>';
}else{
echo '<font color="#CC0000"> <b>輸入錯(cuò)誤</b> </font>';
}
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>確認(rèn)驗(yàn)證碼</title>
</head>
<body>
<form method="post" action="./form.php">
<p>驗(yàn)證碼圖片:<img id="captcha_img" border="1" src="./captcha.php?r=<?php echo rand();?>" width:100px; height:30px" />
<a href="javascript:void(0)" onclick="document.getElementById('captcha_img').src='./captcha.php?r='+Math.random()">換一個(gè)?</a>
<p>請(qǐng)輸入圖片中的內(nèi)容:<input type="text" name="authcode" value="" /></p>
<p><input type="submit" value="提交" ></p>
</form>
</body>
</html>
查看全部 -
驗(yàn)證碼查看全部
-
“寫請(qǐng)求的消耗遠(yuǎn)大于讀請(qǐng)求”
查看全部 -
<?php
session_start();
$captcha_code='';
for($i=0;$i<4;$i++){
$data='abcdefghigkmnpqrstuvwxy13456789';
$fontcontent=substr($data,rand(0,strlen($data)-1),1);
? ? ? ??
$captcha_code.=$fontcontent;
}
$_SESSION['authcode']=$captcha_code;
echo $_SESSION['authcode'];
//證明session是開著的
/* ?$str = '1';
$str .= '2';
$str .= '3';
$str .='4';
echo $str; 拼接規(guī)則的實(shí)驗(yàn)*/
?>?
查看全部
舉報(bào)