㈠ phpcmsPHPCMS v9 自定義表單添加驗證碼驗證
要在PHPCMS v9系統中自定義表單添加驗證碼驗證,首先需要在頭部代碼中加入以下代碼:
pc_base::load_sys_class('form', '', 0);
這行代碼的作用是載入系統中的表單類庫。接下來,需要在表單生成代碼中加入驗證碼的相關代碼。具體實現步驟如下:
1. 在需要添加驗證碼的表單頁面中引入驗證碼生成類庫:
pc_base::load_sys_class('verify', '', 0);
2. 在表單生成代碼中,添加生成驗證碼圖片的代碼:
$verify = new Verify();
$verify->entry();
3. 在表單提交處理代碼中,增加驗證用戶輸入的驗證碼是否正確:
if(!preg_match('/^\d{4}$/', $_POST['verifycode'])){
showmsg('驗證碼錯誤!', '', -1);
}
4. 確保在表單中添加驗證碼輸入框和圖片顯示:
<img src="getCheckCodeUrl(); ?>" alt="驗證碼">
通過以上步驟,你就可以在PHPCMS v9的自定義表單中成功添加驗證碼驗證功能,從而提高表單的安全性。
㈡ php實現手機驗證碼驗證注冊功能的邏輯是怎樣的
手機注冊驗證邏輯是這樣的:
首先要找簡訊服務商如:夢網、雲信使、互億無線等等申請簡訊發送介面。
網站實現流程如下:
第一步:用戶注冊時輸入手機號,網站首先要通過JS或者ajax+php驗證這個號碼是不是正確的手機號。
第二步:用戶點擊發送手機驗證碼,通過ajax把手機號傳到php,這時php生成一個隨機的驗證碼保存在session中,然後通過簡訊介面把這個驗證碼發送到這個手機號中。
第三步:用戶輸入手機收到的驗證碼注冊。網站用session中的驗證碼和用戶輸入的驗證碼比較。
㈢ 驗證碼怎麼用php實現
<?php
/*
* Filename: authpage.php
*/
srand((double)microtime()*1000000);
//驗證用戶輸入是否和驗證碼一致
if(isset($HTTP_POST_VARS['authinput']))
{
if(strcmp($HTTP_POST_VARS['authnum'],$HTTP_POST_VARS['authinput'])==0)
echo "驗證成功!";
else
echo "驗證失敗!";
}
//生成新的四位整數驗證碼
while(($authnum=rand()%10000)<1000);
?>
<form action=authpage.php method=post>
<table>
請輸入驗證碼:<input type=text name=authinput style="width:
80px"><br>
<input type=submit name="驗證" value="提交驗證碼">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=authimg.php?authnum=<? echo $authnum; ?>>
</table>
</form>
代碼二:
<?php
/*
* Filename: authimg.php
* Author: hutuworm
* Date: 2003-04-28
* @Copyleft hutuworm.org
*/
//生成驗證碼圖片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
$im = imagecreate(58,28);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,68,30,$gray);
//將四位整數驗證碼繪入圖片
imagestring($im, 5, 10, 8, $HTTP_GET_VARS['authnum'], $black);
for($i=0;$i<50;$i++) //加入干擾象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $black);
}
ImagePNG($im);
ImageDestroy($im);
?>
㈣ php 驗證碼 使用
你訪問http://你地址/上述程序的文件名.php?action=verifycode
這樣就可以看到圖片了,同理插入到登錄框用
<imgsrc="http://你地址/上述程序的文件名.php?action=verifycode"/>
就可以了
-------------------------
leboc代碼你都沒看懂,$_GET["action"]=="verifycode"是判斷動作的,當動作為verifycode的時候調用rand_create()函數產生一個隨機驗證碼.不是你說的
"每個驗證碼不會都是"verifycode"?吧?".而是每次調用驗證碼都要用verifycode
補充回答-----------------------------------
彈出迅雷?請確認你的電腦支持PHP,的運行環境.
我用你的代碼保存為c.php,保存在伺服器上,
同時,建立一個1.html,代碼內容僅為
<imgsrc="c.php?action=verifycode"/>.存放與c.php同一目錄.
運行後是可以正常顯示驗證碼的.
㈤ 驗證碼怎麼驗啊
目前,不少網站為了防止用戶利用機器人自動注冊、登錄、灌水,都採用了
驗證碼技術。所謂驗證碼,就是將一串隨機產生的數字或符號,生成一幅圖片,
圖片里加上一些干擾象素(防止OCR),由用戶肉眼識別其中的驗證碼信息,輸
入表單提交網站驗證,驗證成功後才能使用某項功能。
我們這里展示了如何編寫PHP程序實現驗證碼功能:
代碼一:
<?php
/*
* Filename: authpage.php
* Author: hutuworm
* Date: 2003-04-28
* @Copyleft hutuworm.org
*/
srand((double)microtime()*1000000);
//驗證用戶輸入是否和驗證碼一致
if(isset($HTTP_POST_VARS['authinput']))
{
if(strcmp($HTTP_POST_VARS['authnum'],$HTTP_POST_VARS['authinput'])==0)
echo "驗證成功!";
else
echo "驗證失敗!";
}
//生成新的四位整數驗證碼
while(($authnum=rand()%10000)<1000);
?>
<form action=authpage.php method=post>
<table>
請輸入驗證碼:<input type=text name=authinput style="width: 80px"><br>
<input type=submit name="驗證" value="提交驗證碼">
<input type=hidden name=authnum value=<? echo $authnum; ?>>
<img src=authimg.php?authnum=<? echo $authnum; ?>>
</table>
</form>
代碼二:
<?php
/*
* Filename: authimg.php
* Author: hutuworm
* Date: 2003-04-28
* @Copyleft hutuworm.org
*/
//生成驗證碼圖片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
$im = imagecreate(58,28);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,68,30,$gray);
//將四位整數驗證碼繪入圖片
imagestring($im, 5, 10, 8, $HTTP_GET_VARS['authnum'], $black);
for($i=0;$i<50;$i++) //加入干擾象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $black);
}
ImagePNG($im);
ImageDestroy($im);
?>
本文程序在Apache 2.0.45 + PHP 4.3.1環境下運行通過。
上文只是對驗證碼功能的一個簡單實現,並沒有考慮商用安全性問題。如果要增強安全性,將此功能投入商業應用,則可以通過以下幾個步驟實現:
1. 啟用Session。
2. authnum在authimg.php中生成,並計算md5sum,存入session。
3. authpage.php將authinput計算md5sum後,與session中的authnum(md5sum)對比得出驗證結果。
本站註:作者使用了簡單的代碼實現了很酷的功能。不過在添加干擾像素時的效果不是太好,大家可以看一下雨聲論壇登錄時的效驗碼(http://ror.cn/perl/ut/user_login.cgi),偶把第二段代碼稍改了一下,生成了與其類似的效果。
修改後的代碼如下:
<?php
/*
* Filename: authimg.php
* Author: hutuworm
* Date: 2003-04-28
* @Copyleft hutuworm.org
*/
//生成驗證碼圖片
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);
$im = imagecreate(62,20);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,68,30,$gray);
while(($authnum=rand()%100000)<10000);
//將四位整數驗證碼繪入圖片
imagestring($im, 5, 10, 3, $authnum, $black);
for($i=0;$i<200;$i++) //加入干擾象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>