thinkphpÑéÖ¤Âë¹ýʧ²»Ë¢ÐÂÔõô°ì
thinkphpÊÇÒ»¿î»ùÓÚmvcģʽµÄ¿ªÔ´webÓ¦Óÿò¼Ü£¬ËüÌṩÁËÖî¶àÓÅÒìµÄ¹¦Ð§ºÍÌØÕ÷£¬ÉÁ¿ª·¢ÕßÄܹ»Ô½·¢¸ßЧµØ¿ª·¢webÓ¦Óá£ÆäÖÐÖ®Ò»¼´ÊÇÑéÖ¤Â빦Ч¡£ÑéÖ¤Â룬ȫ³ÆΪ¡°Í¼ÐÎÑéÖ¤Â롱£¬ÊÇÒ»ÖÖÓÃÓÚ±ÜÃâ¶ñÒâ»úеÈË×¢²á»òµÇ¼µÄÊÖÒÕÊֶΡ£Í¨³£ÇéÐÎÏ£¬µ±Óû§ÊäÈë¹ýʧµÄÑéÖ¤Âëʱ£¬ÍøÕ¾»áˢлòÖØÐÂÌìÉúÒ»ÕÅÑéÖ¤ÂëͼƬ¡£¿ÉÊÇÓÐһЩÓû§Óöµ½ÁËthinkphpÑéÖ¤Âë¹ýʧȴ²»Ë¢ÐµÄÎÊÌ⣬ÕâÊÇÔõô»ØÊÂÄØ£¿
Ò»¡¢ÎÊÌâÐÎò
ThinkphpÖУ¬ÑéÖ¤ÂëµÄÌìÉúºÍУÑéʹÓõÄÊÇThinkphp×Ô´øµÄÑéÖ¤ÂëÀà¿â¡£ÔÚʹÓøÃÀà¿âʱ£¬Óû§»á·¢Ã÷·ºÆðÁËÒ»ÖÖÇéÐΣ¬¼´µ±ÑéÖ¤ÂëÊäÈë¹ýʧʱ£¬ÍøÕ¾²»»áÁ¬Ã¦Ë¢ÐÂÑéÖ¤Âë¡£ÈôÊÇÓû§Ò»Á¬¶à´ÎÊäÈë¹ýʧµÄÑéÖ¤Â룬ÍøÕ¾²¢Ã»ÓиüÐÂÑéÖ¤Â룬ÕâÈÃÓû§¸ÐÓ¦ºÜÊÇδ±ã¡£
¶þ¡¢ÎÊÌâÆÊÎö
¸ÃÎÊÌâµÄ·ºÆðÔµ¹ÊÔÓÉÊÇÓÉÓÚÔÚThinkphpµÄÑéÖ¤ÂëÀà¿âÖУ¬±£´æÒ»¸öÊôÐÔ$resetΪfalseµÄÒªÁì¡£µ±¸ÃÊôÐÔֵΪfalseʱ£¬¼´²»Ë¢ÐÂÑéÖ¤Â룬ֱÖÁÓâÆÚΪֹ¡£ÒÔÊǵ±Óû§¶à´ÎÊäÈë¹ýʧµÄÑéÖ¤Âëʱ£¬ÍøÕ¾²»»á¸üÐÂÑéÖ¤Âë¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
Èý¡¢½â¾öÒªÁì
Õë¶Ô¸ÃÎÊÌ⣬½â¾öÒªÁìÒ²ºÜ¼òÆÓ£¬Ö»ÐèÒª°Ñ$resetÊôÐÔÖµÐÞ¸ÄΪtrue¼´¿É¡£ÐÞ¸ÄÒªÁìÈçÏ£º
ÔÚThinkPHP/Library/Think/Verify.class.phpÖÐÕÒµ½ÒÔÏ´úÂ룺
//ÊÇ·ñ»»ìÏýÇúÏß public $useCurve = true; //ÊÇ·ñÌí¼ÓÔÓµã public $useNoise = true; //ÑéÖ¤ÂëͼƬ¿í¶È public $imageW = 130; //ÑéÖ¤ÂëͼƬ¸ß¶È public $imageH = 50; //ÑéÖ¤ÂëλÊý public $length = 4; //ÑéÖ¤Âë×ÖÌå¾Þϸ(px) public $fontSize = 25; //ÊÇ·ñ»ÑÕÉ«Åä¾° public $useZh = false; //ÑéÖ¤ÂëÖÖ×Ó protected $seed = '123456789QWERTYUIOPASDFGHJKLZXCVBNM'; //ÌìÉúÑéÖ¤Âë public function entry(){ //ÑéÖ¤Âë×Ö·û $this->code = $this->makeCode(); session($this->seKey,$this->code);//ÑéÖ¤ÂëÉúÑĵ½SESSIONÖÐ $width = ($this->length* $this->fontSize*0.9 + $this->fontSize*1.5); $height = $this->fontSize*2; if( $this->useZh ){ $width = 230; $height = 50; } //½¨ÉèͼÏñ $this->image = imagecreate($width,$height); //ÉèÖÃÅä¾° if($this->useZh) imagecolorallocate($this->image,244, 220, 215); else{ $this->bkcolor = imagecolorallocate($this->image, 255, 255, 255); imagefill($this->image,0,0,$this->bkcolor); } //»ìÏýÇúÏß if ($this->useCurve) { $this->writeCurve(); } //ÔÓµã if ($this->useNoise) { $this->writeNoise(); } //ÑéÖ¤Âë $this->writeCode(); header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate"); header("Content-type: image/png;charset=utf8"); imagepng($this->image); imagedestroy($this->image); }
µÇ¼ºó¸´ÖÆ
½«ÆäÖеÄ$resetÊôÐÔÖµÐÞ¸ÄΪtrue£¬Ð޸ĺóµÄ´úÂëÈçÏ£º
//ÊÇ·ñ»»ìÏýÇúÏß public $useCurve = true; //ÊÇ·ñÌí¼ÓÔÓµã public $useNoise = true; //ÑéÖ¤ÂëͼƬ¿í¶È public $imageW = 130; //ÑéÖ¤ÂëͼƬ¸ß¶È public $imageH = 50; //ÑéÖ¤ÂëλÊý public $length = 4; //ÑéÖ¤Âë×ÖÌå¾Þϸ(px) public $fontSize = 25; //ÊÇ·ñ»ÑÕÉ«Åä¾° public $useZh = false; //ÑéÖ¤ÂëÖÖ×Ó protected $seed = '123456789QWERTYUIOPASDFGHJKLZXCVBNM'; //ÌìÉúÑéÖ¤Âë public function entry(){ //ÑéÖ¤Âë×Ö·û $this->code = $this->makeCode(); session($this->seKey,$this->code);//ÑéÖ¤ÂëÉúÑĵ½SESSIONÖÐ $width = ($this->length* $this->fontSize*0.9 + $this->fontSize*1.5); $height = $this->fontSize*2; if( $this->useZh ){ $width = 230; $height = 50; } //½¨ÉèͼÏñ $this->image = imagecreate($width,$height); //ÉèÖÃÅä¾° if($this->useZh) imagecolorallocate($this->image,244, 220, 215); else{ $this->bkcolor = imagecolorallocate($this->image, 255, 255, 255); imagefill($this->image,0,0,$this->bkcolor); } //»ìÏýÇúÏß if ($this->useCurve) { $this->writeCurve(); } //ÔÓµã if ($this->useNoise) { $this->writeNoise(); } //ÑéÖ¤Âë $this->writeCode(); // ÒÔÏÂΪ´úÂëÐÞ¸Ä $this->reset = true; header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate"); header("Content-type: image/png;charset=utf8"); imagepng($this->image); imagedestroy($this->image); }
µÇ¼ºó¸´ÖÆ
ÐÞ¸ÄÍêºó£¬ÉúÑIJ¢ÖØÐÂÌá½»¼´¿É¡£
ËÄ¡¢½áÂÛ
±¾ÎÄÏÈÈÝÁËThinkphpÑéÖ¤Âë¹ýʧ²»Ë¢ÐµÄÎÊÌâ·ºÆðÔµ¹ÊÔÓÉÏ¢Õù¾öÒªÁì¡£Ö»ÐèÐÞ¸ÄÒ»ÐдúÂ룬¼´¿É½â¾ö¸ÃÎÊÌâ¡£ÏÖʵÉÏ£¬ÔÚʹÓÃÈκοò¼Üʱ£¬·ºÆðÎÊÌâµÄÇéÐζ¼ÊDz»¿É×èÖ¹µÄ¡£²»¹ýÖ»ÒªÎÒÃÇÆð¾¢µØȥѰÕÒ½â¾öÒªÁ죬ÎÊÌâ×ܻᱻ½â¾ö¡£
ÒÔÉϾÍÊÇthinkphpÑéÖ¤Âë¹ýʧ²»Ë¢ÐÂÔõô°ìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡