thinkphp3.2.3ÑéÖ¤Âë²»ÏÔʾÔõô°ì
×÷Ϊһ¸öphp¿ª·¢Ö°Ô±£¬¾³£»áʹÓõ½thinkphp¿ò¼Ü£¬¶øÑéÖ¤ÂëÊÇÍøÕ¾Çå¾²±£»¤µÄÒ»µÀÖ÷Òª¹Ø¿¨£¬¿ÉÊÇÓÐʱ¼äÔÚʹÓÃthinkphp3.2.3¿ò¼Üʱ£¬ÎÒÃÇ»áÓöµ½ÑéÖ¤Âë²»ÏÔʾµÄÎÊÌ⣬ÕâÈÃÎÒÃǺÜÊÇÒÉÐÄ¡£ÄÇô£¬¸ÃÔõô½â¾öÄØ£¿
Ê×ÏÈ£¬ÈÃÎÒÃÇÏàʶһÏÂÑéÖ¤ÂëÌìÉúµÄÁ÷³Ì¡£ÔÚThinkPHPÀÑéÖ¤ÂëÊÇͨ¹ý½¨ÉèÒ»¸öͼƬÀ´ÊµÏֵģ¬¶øThinkPHPĬÈÏʹÓõÄÊÇGD¿âÀ´ÌìÉúͼƬ¡£¼òÆÓÀ´Ëµ£¬¾ÍÊÇͨ¹ýÌìÉúÒ»¸ö´øÓÐ×ÌÈÅÏß¡¢×ÌÈŵãºÍËæ»ú×Ö·ûµÄͼƬÀ´ÊµÏÖÑéÖ¤ÂëµÄÌìÉú¡£ÄÇô£¬ÈôÊÇÑéÖ¤Âë²»ÏÔʾ£¬ÍùÍù¾ÍÊÇÓÉÓÚͼƬÌìÉúʧ°Üµ¼Öµġ£
Õë¶ÔÕâ¸öÎÊÌ⣬ÎÒÃÇ¿ÉÒÔ¾ÙÐÐÒÔϼ¸¸ö°ì·¨µÄʵÑ飬À´½â¾öÑéÖ¤Âë²»ÏÔʾµÄÎÊÌâ¡£
°ì·¨Ò»£º¼ì²éÊÇ·ñ¿ªÆôsession
Ê×ÏÈ£¬ÎÒÃÇÐèÒª¼ì²éÊÇ·ñÒѾ¿ªÆôÁËsession¡£ÓÉÓÚÑéÖ¤ÂëµÄÌìÉúÐèҪʹÓÃsessionÀ´ÉúÑÄÑéÖ¤ÂëµÄÖµ£¬ÈôÊÇûÓпªÆôsession£¬¾Í²»¿ÉÕý³£ÌìÉúÑéÖ¤Âë¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¼ì²ésessionµÄ¿ªÆô״̬¿ÉÒÔÔÚconfig.phpÖÐÉó²é£¬·¿ªconfig.phpÎļþ£¬ÔÚreturnÊý×éÖÐÌí¼ÓÒÔÏ´úÂ룺
'session_auto_start' => true,
µÇ¼ºó¸´ÖÆ
¸Ã´úÂë¿ÉÒÔÈóÌÐòÔÚÆô¶¯Ê±×Ô¶¯¿ªÆôsession£¬ÈôÊÇÒѾ¿ªÆôÔò²»»áÓ°ÏìÕý³£Ê¹Óá£
°ì·¨¶þ£º¼ì²éGD¿âÊÇ·ñ¿ÉÓÃ
Æä´Î£¬ÎÒÃÇÐèÒª¼ì²éÊÇ·ñÒѾװÖÃÁËGD¿â£¬ÓÉÓÚThinkPHPĬÈÏʹÓõľÍÊÇGD¿âÀ´ÌìÉúÑéÖ¤Âë¡£ÈôÊÇûÓÐ×°ÖûòÕßÎÞ·¨Ê¹ÓÃGD¿â£¬ÄÇô¾Í²»¿ÉÕý³£ÌìÉúÑéÖ¤Âë¡£
¼ì²éÊÇ·ñ×°ÖÃÁËGD¿â¿ÉÒÔÉó²éphp.iniÎļþÖÐÊÇ·ñÒѾ°Ñgd2Õâ¸öÄ£¿é½âѹ ²¢ÇÒextension=php_gd2.dll;extension=php_mbstring.dll;extension=php_exif.dllÈý¸öÄ£¿éËùÓн⿪עÊÍ¡£
ÕÒµ½php.iniÎļþÖÐÒÔÏÂÁ½¸öÐÐÉèÖãº
extension=php_gd2.dll;
µÇ¼ºó¸´ÖÆ
extension=php_mbstring.dll;
µÇ¼ºó¸´ÖÆ
ÈôÊÇÇ°ÃæûÓзֺÅ;£¬ËµÃ÷GD¿âÒѾ׼ȷװÖá£
°ì·¨Èý£º¼ìÄ¥Á·Ö¤ÂëÌìÉúĿ¼ÊÇ·ñ¿Éд
ÑéÖ¤ÂëÌìÉúʱÐèÒª½«ÌìÉúµÄͼƬÉúÑÄÔÚЧÀÍÆ÷ÉÏ£¬Òò´ËÎÒÃÇ»¹ÐèÒª¼ìÄ¥Á·Ö¤ÂëÌìÉúĿ¼ÊÇ·ñ¿Éд¡£ÈôÊÇÌìÉúĿ¼ûÓÐȨÏÞ»òÕß²»±£´æ£¬¾Í»áµ¼ÖÂÑéÖ¤ÂëÎÞ·¨Õý³£ÌìÉú¡£
ÎÒÃÇ¿ÉÒÔÔÚconfig.phpÎļþÖÐÌí¼ÓÈçÏ´úÂëÀ´ÉèÖÃÑéÖ¤ÂëÌìÉúĿ¼£º
'captcha' =>array( 'fontSize' => 30, //ÑéÖ¤Âë×ÖÌå¾Þϸ 'length' => 4, //ÑéÖ¤ÂëλÊý 'useCurve' => false, //ÊÇ·ñ»»ìÏýÇúÏß 'useNoise' => false, //ÊÇ·ñÌí¼ÓÔÓµã 'fontttf' => '5.ttf', //ÑéÖ¤Âë×ÖÌ壬²»ÉèÖÃËæ»ú»ñÈ¡ 'bg' => array(243, 251, 254), //Åä¾°ÑÕÉ« 'reset' => true //ÑéÖ¤ÀֳɺóÊÇ·ñÖØÖà ),
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÊý×éÖУ¬ÎÒÃÇ¿ÉÒÔ×Ô½ç˵ÑéÖ¤ÂëµÄ³¤¶È¡¢ÊÇ·ñ»æÖÆ»ìÏýÇúÏß¡¢ÊÇ·ñÌí¼ÓÔӵ㡢×ÖÌåÎļþ·¾¶µÈµÈ¡£Ëü»¹ÔÊÐíÎÒÃÇΪÑéÖ¤ÂëÌìÉúĿ¼×Ô½ç˵һ¸öÃû×Ö£¬¶øÕâ¸öĿ¼±ØÐèÊÇ¿ÉдµÄ¡£
ÀýÈ磬ÈôÊÇÉèÖÃÑéÖ¤ÂëÌìÉúĿ¼ΪApplication/Runtime/Cache/Ŀ¼£¬ÄÇôÎÒÃÇÐèҪȷ±£¸ÃĿ¼ÊÇ¿ÉдµÄ£¬²»È»»áµ¼ÖÂÑéÖ¤ÂëÎÞ·¨ÏÔʾ¡£
°ì·¨ËÄ£ºÊµÑé¸Ä±äÑéÖ¤ÂëΪurlģʽ
ÈôÊÇÒÔÉÏ°ì·¨¼ì²éûÓз¢Ã÷ÎÊÌ⣬ÄÇôÎÒÃÇ¿ÉÒÔʵÑéʹÓÃThinkPHPÌṩµÄUrlģʽÌìÉúÑéÖ¤Âë¡£¸ÃģʽʹÓÃÁËHTML5µÄcanvas±êÇ©£¬¿ÉÒÔÌìÉú¶¯Ì¬µÄÑéÖ¤Â룬Äܹ»¸üºÃµØ±ÜÃâ»úеÈ˹¥»÷ºÍ±©Á¦Æƽ⡣
ÎÒÃÇ¿ÉÒÔÔÚconfig.phpÎļþÖÐÌí¼ÓÒÔÏ´úÂëÀ´ÉèÖÃÌìÉúÑéÖ¤ÂëµÄurlģʽ£º
'captcha' => true,
µÇ¼ºó¸´ÖÆ
Õ⽫»áÌìÉúÒ»¸öĬÈϵÄURLµØµã£¬ÈçÏÂËùʾ£º
<img alt="thinkphp3.2.3ÑéÖ¤Âë²»ÏÔʾÔõô°ì" >
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÕâÀïµÄ__APP__ÊÇϵͳÌṩµÄ±äÁ¿£¬ÌåÏÖÄ¿½ñÓ¦ÓóÌÐòµÄ¸ùĿ¼£¬¶øverify¾ÍÊÇÎÒÃÇÌìÉúÑéÖ¤ÂëµÄ¿ØÖÆÆ÷ÒªÁìÃû¡£
ÕâÖÖ·½·¨¿ÉÄÜ»áÓöµ½ä¯ÀÀÆ÷»º´æµÄÎÊÌ⣬²¢ÇÒ»áÈÃÒ³Ãæ±äµÃÓ·Öס£Òò´Ë£¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃСÖÚµÄJavaScript´úÂ룬ÔÚÌìÉúÑéÖ¤ÂëµÄͬʱɨ³ýä¯ÀÀÆ÷»º´æ£¬´Ó¶ø½â¾öµôÕâ¸öÎÊÌâ¡£
ÔÚHTMLÒ³ÃæÖУ¬ÎÒÃÇ¿ÉÒÔÕâÑùд£º
<img alt="thinkphp3.2.3ÑéÖ¤Âë²»ÏÔʾÔõô°ì" >
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÔÚJavaScriptÖУ¬ÎÒÃÇ¿ÉÒÔÕâÑùд£º
$(function(){ $('#verify_img').click(function(){ var timenow = new Date().getTime(); $(this).attr('src','/Home/Public/verify/' + timenow); }); });
µÇ¼ºó¸´ÖÆ
Õâ¸öJavaScript´úÂë»áÔÚÿ´Îµ¥»÷ÑéÖ¤ÂëͼƬʱ£¬¶¯Ì¬ÌìÉúÒ»¸öʱ¼ä´Á£¬Ê¹Æä³ÉΪURLµÄÒ»²¿·Ö£¬È·±£Ã¿´Î»á¼ûÑéÖ¤Âëʱ¶¼ÊÇÒ»¸öеÄURLµØµã£¬´Ó¶øÓÐÓÃ×èÖ¹ÁËä¯ÀÀÆ÷»º´æÎÊÌâ¡£
×ܽá
ͨ¹ýÒÔÉÏÕâЩ³£¼ûµÄ½â¾ö·½·¨£¬ÎÒÃÇ¿ÉÒÔÓÐÓõؽâ¾öThinkPHP3.2.3ÑéÖ¤Âë²»ÏÔʾµÄÎÊÌâ¡£ÔÚÏÖʵ¿ª·¢ÏîÄ¿ÖУ¬ÎÒÃÇÒ²ÐèÒª×ñÕÕÕâЩ¹æ·¶£¬°ü¹Ü³ÌÐòµÄÕý³£ÔËÐУ¬¸üºÃµØ±£»¤Óû§µÄÒþ˽ºÍÊý¾ÝÇå¾²¡£Í¬Ê±£¬ÎÒÃÇÒ²Ó¦¸Ãʱ¿Ì¹Ø×¢Çå¾²ÎÊÌ⣬һֱѧϰºÍ̽ÌÖеıÜÃâÍøÕ¾¹¥»÷µÄÊÖÒÕ£¬ÎªÍøÕ¾Çå¾²±£¼Ý»¤º½¡£
ÒÔÉϾÍÊÇthinkphp3.2.3ÑéÖ¤Âë²»ÏÔʾÔõô°ìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡