thinkphpµÇ¼¼ì²âÔõôʵÏÖ
Ò»£ºThinkPHPµÇ¼¼ì²âÊÇʲô
ThinkPHPµÇ¼¼ì²âÊÇÖ¸µ±Óû§ÊµÑéµÇ¼ºó£¬ÏµÍ³»áͨ¹ýÑéÖ¤Óû§ÊäÈëµÄÐÅÏ¢ÊÇ·ñÓëϵͳÖеÄÓû§Êý¾ÝÏà¶ÔÓ¦£¬ÈôÊÇÑé֤ͨ¹ý£¬Ôò¿ÉÒÔ¾ÙÐÐÊÚȨ´¦Öóͷ££¬È»ºóÏÔʾÏìÓ¦µÄÒ³ÃæÄÚÈÝ¡£Ê¹ÓÃThinkPHP¿ò¼ÜÌṩµÄ¿âºÍº¯Êý£¬½«¸ÃÀú³Ì¾ÙÐм¯³É¡£
¶þ£ºThinkPHPµÇ¼¼ì²âµÄÁ÷³ÌÊÇʲô
Óû§ÔڵǼҳÃæÊäÈëÓû§ÃûºÍÃÜÂ룬²¢Ìá½»µÇ¼ÇëÇó¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
³ÌÐòÎüÊÕµ½µÇ¼ÇëÇ󣬲¢¶ÔÓû§ÃûºÍÃÜÂë¾ÙÐÐÑéÖ¤¡£ÈôÊÇÑé֤ͨ¹ý£¬¿ªÆô»á»°¡£
³ÌÐò»á¼ÍÈÎÃü»§µÄµÇ¼״̬£¬È»ºó½«Óû§×ªÒƵ½ÊÚȨҳÃæ¡£
³ÌÐò½«¼ì²éÓû§µÄ½ÇÉ«ºÍȨÏÞ£¬ÈôÊÇÓû§È¨ÏÞµÖ´ï»®¶¨µÄÒªÇó£¬Ôò¿ÉÒÔÏÔʾҳÃæÄÚÈÝ¡£
Óû§ÔÊÐíÊÚȨºó£¬³ÌÐò»á¼ÓÔØÒ³ÃæÄÚÈݲ¢½«ÄÚÈÝ´«ËÍ»ØÓû§¶Ë¡£
Èý£ºThinkPHPÔõÑù¾ÙÐеǼ¼ì²â
ÔÚThinkPHPÖУ¬¿ÉÒÔʹÓÃsessionºÍcookie»úÖÆʵÏֵǼÑéÖ¤¡£Ïêϸ°ì·¨ÈçÏ£º
½«Óû§µÇ¼µÄÓû§Êý¾ÝÉúÑÄÔÚsessionÖС£
ÔÚÐèÒª¾ÙÐÐȨÏÞÑéÖ¤µÄ¿ØÖÆÆ÷ºÍÄ£°æÒ³ÃæÖУ¬Ê¹ÓÃsessionÅжÏÓû§ÊÇ·ñÒѾµÇ¼¡£
¹ØÓÚÐèÒªÉó²é»á¼ûȨÏÞµÄÒ³Ã棬¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐʹÓÃacl²å¼þ¾ÙÐмì²é¡£
ÔÚphp´úÂëÖÐŲÓÃÓû§Ä£×ÓÀ´¼ì²éÓû§½ÇÉ«ºÍȨÏÞ£¬Åжϻá¼ûÊÇ·ñÔÊÐí¡£
ËÄ£ºThinkPHPµÇ¼¼ì²âµÄʵÀýÑÝʾ
¼ÙÉèÎÒÃÇÒѾÓÐÒ»¸öÓû§µÇ¼ҳÃ棬ÎÒÃÇ¿ÉÒÔ½ÓÄÉÏÂÃæµÄÒªÁìÔÚThinkPHPÖÐʵÏֵǼ¼ì²â¡£
ÐèÒªÔڵǼҳÃæµÄ¿ØÖÆÆ÷ÖоÙÐÐÓû§ÐÅÏ¢ÑéÖ¤£¬ÈôÊÇͨ¹ý£¬½«Óû§ÐÅÏ¢ÉúÑĵ½»á»°ÖС£´ËÀú³Ì¿ÉÒÔͨ¹ý´úÂë $this->session(‘user’, $user) À´Íê³É¡£
½ç˵һ¸ö¿ØÖÆÆ÷À࣬²¢ÔÚÆäÖоÙÐÐȨÏÞ¼ì²é¡£ÊÚȨ¼ì²é¿ÉÒÔʹÓÃÀàËÆÒÔϵķ½·¨£º
if (!$this->checkAccess($controller . '/' . $action)) { return $this->error('ûÓлá¼ûȨÏÞ'); }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬checkAccessº¯Êý»áÔÚºǫ́¼ì²éÓû§½ÇÉ«ºÍȨÏÞ¡£ÈôÊÇͨ¹ý¼ì²é£¬Ôò·µ»Øtrue¡£
ÔÚ¿ØÖÆÆ÷ÖУ¬ÎÒÃÇÐèÒª½ç˵Éó²é»á¼ûȨÏÞµÄÒªÁì¡£Ò»Ñùƽ³£¿ÉÒÔ½ÓÄÉÒÔϵÄʵÏÖ·½·¨¡£
protected function checkAccess($path) { $access = $this->getAccessList(); if (!isset($access['allow'][$path])) { return false; } return true; }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬getAccessListº¯Êý»á·µ»Ø½ÇÉ«ºÍȨÏÞÁÐ±í¡£
ÒÔÉϾÍÊÇthinkphpµÇ¼¼ì²âÔõôʵÏÖµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡