2022-08-26 10:48:04 - 米境通
magento注冊(cè)頁面添加驗(yàn)證碼
captcha
一:app/code/local/Mage/Customer/controllers/CapthchasController.php
Header("Content-type:image/PNG");
classMage_Customer_CapthchasControllerextendsMage_Core_Controller_Front_Action
{
publicfunctiongetCode($num=4,$w=6,$h=20){
//header("Content-type:text/html;charset=utf-8");
session_start();
//去掉了01Ol等
$str="23456789abcdefghijkmnpqrstuvwxyz";
$code='';
for($i=0;$i<$num;$i++){
$code.=$str[mt_rand(0,strlen($str)-1)];
}
//將生成的驗(yàn)證碼寫入session,備驗(yàn)證頁面使用
$_SESSION["helloweba_char"]=$code;
//創(chuàng)建圖片,定義顏色值
$im=imagecreate($w,$h);
$black=imagecolorallocate($im,mt_rand(0,200),mt_rand(0,120),mt_rand(0,120));
$gray=imagecolorallocate($im,118,151,199);
$bgcolor=imagecolorallocate($im,235,236,237);
//畫背景
imagefilledrectangle($im,0,0,$w,$h,$bgcolor);
//畫邊框
imagerectangle($im,0,0,$w-1,$h-1,$gray);
//imagefill($im,0,0,$bgcolor);
//在畫布上隨機(jī)生成大量點(diǎn),起干擾作用;
for($i=0;$i<80;$i++){
imagesetpixel($im,rand(0,$w),rand(0,$h),$black);
}
//將字符隨機(jī)顯示在畫布上,字符的水平間距和位置都按一定波動(dòng)范圍隨機(jī)生成
$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,14);
}
$te=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//字體顏色
imagepng($im);
imagedestroy($im);
imagettftext($im,12,3,20,20,$te,'t1.ttf',$str);
}
publicfunctionindexAction(){
$this->getCode(4,60,20);
}
}
二:appdesignfrontenddefaultdefault emplatepersistentcustomerform
$base_url=$this->getBaseUrl();
if(strstr($base_url,'index.php')=='index.php/'){
$base_url=str_replace('index.php/','',$base_url);
}