thinkphpµÇ¼ºóÔõôÌøת
ÔÚÍøÕ¾µÄ¿ª·¢ÖУ¬µÇ¼ÊǺÜÊÇÖ÷ÒªµÄÒ»¸ö¹¦Ð§£¬µ±Óû§ÀֳɵǼºó£¬Ìøתµ½ºÏÊʵÄÒ³ÃæÒ²ÊÇÐëÒªµÄ£¬ÈÃÓû§¿ÉÒÔ¸üºÃµÄʹÓÃÍøÕ¾¡£ÔÚʹÓà thinkphp ¿ò¼Ü¾ÙÐпª·¢Ê±£¬ÔõÑùʵÏֵǼºóµÄÌøתÄØ£¿ÏÂÃæÎÒÃÇÀ´Ïêϸ¿´Ò»Ï¡£
Ê×ÏÈ£¬ÔڵǼÑéÖ¤Àֳɺó£¬ÎÒÃÇÐèÒª¶ÔÓû§¾ÙÐÐÉí·ÝÑéÖ¤²¢½«Óû§×´Ì¬Ð´Èë session¡£
public function login() { // »ñÈ¡Óû§ÊäÈëµÄÓû§ÃûºÍÃÜÂë $username = $this->request->param('username'); $password = $this->request->param('password'); // ¶Ô»ñÈ¡µ½µÄ²ÎÊý¾ÙÐÐÅжϺʹ¦Àí if(empty($username) || empty($password)) { $this->error('Óû§ÃûºÍÃÜÂë²»¿ÉΪ¿Õ'); } // ÅÌÎÊÓû§ÐÅÏ¢ $user = Db::name('user')->where('username',$username)->find(); if(empty($user)) { $this->error('Óû§Ãû²»±£´æ'); } // ÑéÖ¤ÃÜÂëÊÇ·ñ׼ȷ if(md5($password) !== $user['password']) { $this->error('ÃÜÂë¹ýʧ'); } // ½«Óû§µÄÐÅϢдÈë session session('user_id',$user['id']); session('user_info',$user); // µÇ¼Àֳɺó¾ÙÐÐÌøת $this->redirect('/index'); }
µÇ¼ºó¸´ÖÆ
ÔÚÒÔÉÏ´úÂëÖУ¬ÎÒÃÇÊ×ÏÈ»ñÈ¡Óû§ÊäÈëµÄÓû§ÃûºÍÃÜÂ룬ȻºóÅÌÎÊÓû§ÊÇ·ñ±£´æ£¬ÑéÖ¤ÃÜÂëÊÇ·ñ׼ȷ£¬ÈôÊǶ¼×¼È·£¬Ôò½«Óû§ÐÅϢдÈë session¡£½ÓÏÂÀ´£¬ÎÒÃǾͿÉÒÔͨ¹ý$this->redirect()¾ÙÐÐÒ³ÃæµÄÌøתÁË¡£
$this->redirect('/index');
µÇ¼ºó¸´ÖÆ
²ÎÊýÖеÄ/indexÌåÏÖÌøתµ½ÏîÄ¿µÄ¸ùĿ¼Ï嵀 index ÒªÁ죬¼´Ä¬ÈϵÄÊ×Ò³¡£ÈôÊÇÎÒÃÇÏ£ÍûÌøתµ½ÆäËûµÄÒ³Ã棬ÀýÈ繺Îï³µÒ³Ã棬ֻÐèÒªÐ޸IJÎÊý¼´¿É¡£
$this->redirect('/cart/index');
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëÌåÏÖÌøתµ½¸ùĿ¼Ï嵀 Cart ¿ØÖÆÆ÷Ï嵀 index ÒªÁìÖС£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÁíÍ⣬ÎÒÃÇÒ²¿ÉÒÔÖ±½ÓÌøתµ½Ä³Ò»¸öÏêϸµÄ URL£¬²»¹ýÐèҪעÖصÄÊÇ£¬ÐèҪʹÓÃÏà¶Ô·¾¶Ìøת¡£
$this->redirect('/html/index.html');
µÇ¼ºó¸´ÖÆ
»¹ÐèҪעÖصÄÒ»µãÊÇ£¬redirect()ÒªÁìĬÈÏÊǾÙÐÐÁË 302 Öض¨Ïò£¬ÈôÊÇÎÒÃÇÐèÒª¾ÙÐÐÓÀÊÀÐÔµÄÌøת£¬¿ÉÒÔʹÓòÎÊýÀ´Ö¸¶¨¡£
$this->redirect('/index',301);
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇÒÔ ThinkPHP ¿ò¼ÜΪÀý£¬ÊµÏֵǼºóÌøתµÄÒªÁì¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ»¹ÐèҪƾ֤×Ô¼ºµÄÐèÇóÀ´¾ÙÐÐÐ޸ĺ͵÷½â£¬ÈôÊÇÓÐÈκÎÎÊÌâ¿ÉÒÔÔÚ̸ÂÛÇøÁôÑÔ¡£
ÒÔÉϾÍÊÇthinkphpµÇ¼ºóÔõôÌøתµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡