導航:首頁 > 編程語言 > php遠程驗證碼

php遠程驗證碼

發布時間:2022-07-29 22:09:08

1. php驗證碼問題


<?php
有關生成驗證碼的代碼
?>
換成<img
src="yzm.php">
即可
yzm.php 上面
session_start()
前面的注釋也要去掉,而且裡面很多變數沒有定義,如果PHP.INI開了錯誤提示,就是出錯,提示變數不存在,就不會顯示驗證碼。
login.php裡面,空格
符應該是

不是
nbps
我寫好了,放在我網站上了,演示效果網址:
http://dev.qkweb.net/php/yzm/login.php
下載代碼的地址是:
http://dev.qkweb.net/php/yzm/20110701yzm.rar

2. php驗證碼怎麼使用

把以上代碼保存成code.php,上傳到相應目錄,如網站根目錄 調用的時候 <img src="code.php"> 即可

3. PHP 驗證碼怎樣設置

補充:

驗證碼可以同cookie或者session的方式傳遞數據,
不用有特別的設置,不過要安裝GD庫,否則不能顯示圖片.

隨便放在哪裡都可以,

顯示是以圖片方式顯示,

例如驗證碼的程序文件是ck.php

那麼顯示就是
<img src = "ck.php">

驗證碼有很多種編寫方式,當然是眾說紛紜,
凡是程序都不會有一個統一的格式,只有統一的思路.

4. php的驗證碼提示怎樣製作

一般製作驗證碼會按照下面的幾步走:
一:創建出來一個圖片,通常我們成為源,可以用imagecreatetruecolor()這個函數搞定
二:給這個源 添加背景色,同時設置文本顯示的顏色,GD庫函數為我們提供了imagecolorallocate()函數
三:材料弄好了,我們要給它添點內容了,就是我們隨機生成的數字或者字母,甚至可以是它們的組合,這里我們可以選擇兩個函數 imagettftext()、imagesrting(),這兩個函數的不同,我們會在後面講解。
例:
<?php
session_start();//開啟session,用來記錄獲得的驗證碼,這個函數要寫在程序的開頭,不然會出現錯誤
header(「Content-type :image/gif」);//把文件的返回類型設為image/gif格式,這個格式可以輸出圖片
$codelen=4;//設置你要讓用戶輸入字元的個數,一般為4,過長用戶體驗不好。
$charset =」ABCDEFGHKLMNPRSTUVWYZ23456789″;//我們可以盡量把一些難以辨認的字元去掉,比如阿拉伯數字0和字母o,這也是提高用戶體驗的一種方法。
$code =」;
for($i=0;$i<$codelen;$i++){//用for循環得到4個隨機的字元,在這里用到了mt_rand,這個函數比rand的效率要高的多,建議大家用這個
$code .=$charset{mt_rand(0,strlen($charset)-1)};
}
$_SESSION['code']=$code;//下篇關於session驗證的文章將會用到
$width = 80;
$height = 40;
$im = imagecreatetruecolor($width,$height);//用imagecreatetruecolor()函數來建立一個新的圖片,裡面的兩個數值分別是寬度和高度,這是製作驗證碼的第一步
$bg = imagecolorallocate($im,255,255,0); //圖片背景的顏色,這里是第二步
$textcolor = imagecolorallocate($im,255,0,0);//文字的顏色
imagefill($im,0,0,$bg);//給圖片填充背景色
//好了上面的鋪墊任務做的差不多了,現在關鍵就是讓字元顯示在圖片上,這里有兩種方法我們一一介紹。
$font =」ggbi.ttf」;//如果你有字體的話 就填上字體的相對路徑,如果沒有就留空。下面的兩個用法我會一一講解。
if($font!==」"){
for($num=0;$num<4;$num++){
imagettftext($im,mt_rand(12,16),(mt_rand(0,75)+330)%360,5+15*$num,20+mt_rand(2,5),$textcolor,$font,$code[$num]);//這里是第三步
}
}
else{
for($num=0;$num<4;$num++){
imagestring($im,5,10+15*$num,10+mt_rand(0,5),$code[$num],$textcolor);
}
}
header(「Content-type: image/jpeg」);
imagejpeg($im);
?>

5. php實現驗證碼,能給具體的代碼嗎 在這謝謝過各位高手了

index.php:
<?php
/* index.php start*/
if(!empty($_POST)) {
session_start();
if($_POST['seccode'] == $_SESSION['seccode']) {
echo '<script>alert("驗證成功")</script>';
} else {
echo '<script>alert("驗證失敗")</script>';
}
session_destroy();
}
?>
<form action="" method="post" />
<img id="seccode" src="seccode.php?rand=".<?=rand()?> /> <input type="text" name="seccode" /> <input type="submit" value="submit" />
<input type="button" onclick="document.getElementById('seccode').src = 'seccode.php?reload=1&' + Math.random()" value="change one"/>
</form>

<?php
/* index.php end*/
?>

******************************
seccode.php:
<?php
/*seccode.php start*/
session_start();
if(isset($_SESSION['seccode']) && empty($_GET['reload'])) {
$arr = $_SESSION['seccode'];
} else {
for($i=0; $i<4; $i++) {
$arr[] = rand(0, 9);
}
$_SESSION['seccode'] = implode($arr);
}
$im = imagecreate(90, 25);
$backgroundcolor = imagecolorallocate ($im, 255, 255, 255);

for($i = 0; $i < 4; $i++) {
$s = iconv('GBK', 'UTF-8', $arr[$i]);
$x = $i * 20 + mt_rand(0, 4) - 2;// 隨機X
$y = mt_rand(0, 4); // 隨機Y
$angle = mt_rand(0,4);// 隨機角度
$text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255)); // 隨機顏色
imagettftext($im,20, $angle,$x,20+$y,$text_color,"C:\\Windows\\Fonts\\SIMSUN.TTC",$s);
}

// 線條
$linenums = mt_rand(10, 32);
for($i=0; $i <= $linenums; $i++) {
$linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$linex = mt_rand(0, 62);
$liney = mt_rand(0, 25);
imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
}

// 雜點
for($i=0; $i <= 64; $i++) {
$pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
imagesetpixel($im, mt_rand(0, 62), mt_rand(0, 25), $pointcolor);
}

// 邊框
$bordercolor = imagecolorallocate($im , 150, 150, 150);
imagerectangle($im, 0, 0, 89, 24, $bordercolor);

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
/*seccode.php end*/
?>

6. PHP curl模擬登陸阿里媽媽的代碼怎麼寫,告急!

你用firebug看看要什麼參數,然後再看看,有沒有隨機參數,遠程提交表單!!驗證碼先獲取cookies再請求就可以獲取到配套的驗證碼

7. 如何用PHP生成驗證碼

PHP生成驗證碼的原理:使用PHP的GD庫,生成一張帶驗證碼的圖片,並將驗證碼保存在Session中。PHP生成驗證碼的大致流程有:

1、產生一張png的圖片;

2、為圖片設置背景色;

3、設置字體顏色和樣式;

4、產生4位數的隨機的驗證碼;

5、把產生的每個字元調整旋轉角度和位置畫到png圖片上;

6、加入噪點和干擾線防止注冊機器分析原圖片來惡意破解驗證碼;

7、輸出圖片;

8、釋放圖片所佔內存。

session_start();
getCode(4,60,20);

functiongetCode($num,$w,$h){
$code="";
for($i=0;$i<$num;$i++){
$code.=rand(0,9);
}
//4位驗證碼也可以用rand(1000,9999)直接生成
//將生成的驗證碼寫入session,備驗證時用
$_SESSION["helloweba_num"]=$code;
//創建圖片,定義顏色值
header("Content-type:image/PNG");
$im=imagecreate($w,$h);
$black=imagecolorallocate($im,0,0,0);
$gray=imagecolorallocate($im,200,200,200);
$bgcolor=imagecolorallocate($im,255,255,255);
//填充背景
imagefill($im,0,0,$gray);

//畫邊框
imagerectangle($im,0,0,$w-1,$h-1,$black);

//隨機繪制兩條虛線,起干擾作用
$style=array($black,$black,$black,$black,$black,
$gray,$gray,$gray,$gray,$gray
);
imagesetstyle($im,$style);
$y1=rand(0,$h);
$y2=rand(0,$h);
$y3=rand(0,$h);
$y4=rand(0,$h);
imageline($im,0,$y1,$w,$y3,IMG_COLOR_STYLED);
imageline($im,0,$y2,$w,$y4,IMG_COLOR_STYLED);

//在畫布上隨機生成大量黑點,起干擾作用;
for($i=0;$i<80;$i++){
imagesetpixel($im,rand(0,$w),rand(0,$h),$black);
}
//將數字隨機顯示在畫布上,字元的水平間距和位置都按一定波動范圍隨機生成
$strx=rand(3,8);
for($i=0;$i<$num;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos,substr($code,$i,1),$black);
$strx+=rand(8,12);
}
imagepng($im);//輸出圖片
imagedestroy($im);//釋放圖片所佔內存
}

8. 怎樣用PHP製作驗證碼

<?php

//驗證碼類
classValidateCode{
private$charset='';//隨機因子
private$code;//驗證碼
private$codelen=4;//驗證碼長度
private$width=90;//寬度
private$height=40;//高度
private$img;//圖形資源句柄
private$font;//指定的字體
private$fontsize=20;//指定字體大小
private$fontcolor;//指定字體顏色
//構造方法初始化
publicfunction__construct(){
$this->font=dirname(__FILE__).'/font/elephant.ttf';//注意字體路徑要寫對,否則顯示不了圖片
}
//生成隨機碼
privatefunctioncreateCode(){
$_len=strlen($this->charset)-1;
for($i=0;$i<$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$_len)];
}
}
//生成背景
privatefunctioncreateBg(){
$this->img=imagecreatetruecolor($this->width,$this->height);
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);
}
//生成文字
privatefunctioncreateFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]);
}
}
//生成線條、雪花
privatefunctioncreateLine(){
//線條
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}
//雪花
for($i=0;$i<100;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}
//輸出
privatefunctionoutPut(){
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//對外生成
publicfunctiondoimg(){
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//獲取驗證碼
publicfunctiongetCode(){
returnstrtolower($this->code);
}
}

閱讀全文

與php遠程驗證碼相關的資料

熱點內容
戰地聯盟3解壓密碼 瀏覽:803
s型命令 瀏覽:23
php年薪5年 瀏覽:67
如何上網上設個人加密賬戶 瀏覽:44
linux打開ssh服務 瀏覽:78
微信位置可以加密嗎 瀏覽:470
演算法蠻力法 瀏覽:438
隨機排練命令 瀏覽:147
python多進程並發 瀏覽:41
安卓軟體安裝如何躲避安全檢測 瀏覽:647
奇幻潮翡翠台源碼百度雲盤 瀏覽:187
什麼軟體可以免費pdf轉word 瀏覽:15
php正則表達式大全 瀏覽:394
androidntp時間 瀏覽:299
輪機長命令簿英文 瀏覽:148
oppo鈴聲設置被加密怎麼處理 瀏覽:548
粵苗app圖形驗證碼怎麼填 瀏覽:899
管家婆架設雲伺服器 瀏覽:254
php的登錄界面代碼 瀏覽:997
php開發客戶端 瀏覽:998