thinkphp×Ô½ç˵Ìøת
ÔÚweb¿ª·¢ÖУ¬¾³£ÐèÒªÔÚ³ÌÐòÖоÙÐÐÌøת£¬ÔÚthinkphpÖУ¬¿ÉÒÔʹÓÃϵͳ×Ô´øµÄÌøתº¯Êý¾ÙÐÐÌøת£¬ÀýÈçʹÓÃredirectº¯ÊýʵÏÖÖض¨Ïò¡£¿ÉÊÇÔڴ󲿷ÖÇéÐÎÏ£¬ÏµÍ³×Ô´øµÄÌøתº¯ÊýÎÞ·¨Öª×ãÎÒÃǵÄÐèÇó£¬Õâʱ¼äÎÒÃǾÍÐèÒª×Ô½ç˵Ìøתº¯Êý¡£
ÔÚthinkphpÖУ¬×Ô½ç˵Ìøתº¯Êý¿ÉÒÔͨ¹ýÔÚ¿ØÖÆÆ÷ÖбàдҪÁìʵÏÖ¡£ÏÂÃæÎÒÃÇÒÔÒ»¸ö¼òÆÓµÄʾÀýÀ´Õ¹Ê¾ÔõÑù×Ô½ç˵Ìøתº¯Êý¡£
¼ÙÉèÎÒÃÇÐèҪʵÏÖÒ»¸öÌøתº¯Êý£¬¸Ãº¯Êý¿ÉÒÔÌøתµ½Ö¸¶¨µÄURL£¬Í¬Ê±¿ÉÒÔÔÚÌøתµÄʱ¼äת´ï²ÎÊý¡£Ê×ÏÈÎÒÃÇÐèÒªÔÚ¿ØÖÆÆ÷Öнç˵һ¸öÒªÁ죬¸ÃÒªÁìµÄ²ÎÊý°üÀ¨ÒªÌøתµÄURLºÍҪת´ïµÄ²ÎÊý¡£
public function myRedirect($url, $params = []) { $params_str = ''; if(!empty($params)) { $params_str = http_build_query($params); $params_str = '&' . $params_str; } header('Location: ' . $url . $params_str); exit; }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÊ×ÏȽ«×ª´ïµÄ²ÎÊý×é×°³ÉÒ»¸öÅÌÎÊ×Ö·û´®£¬È»ºó½«Õû¸öURLºÍ²ÎÊý×Ö·û´®Æ´½Ó£¬×îºóʹÓÃheaderº¯Êý¾ÙÐÐÌøת¡£ÈôÊÇÌøתÀֳɺó£¬ÎÒÃÇ»¹ÐèҪŲÓÃexitº¯ÊýÀ´ÖÕÖ¹³ÌÐòµÄÖ´ÐС£
ʹÓÃ×Ô½ç˵Ìøתº¯Êýʱ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚ¿ØÖÆÆ÷µÄÒªÁìÖÐŲÓÃmyRedirectº¯ÊýÀ´ÊµÏÖÌøת¡£ÀýÈ磺
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
public function index() { $params = [ 'name' => 'thinkphp', 'version' => '5.1' ]; $url = 'https://www.thinkphp.cn'; $this->myRedirect($url, $params); }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄʾÀýÖУ¬ÎÒÃÇÔÚindexÒªÁìÖÐŲÓÃmyRedirectº¯Êý¾ÙÐÐÌøת£¬Í¬Ê±×ª´ïÁËÒ»¸öÃûΪ$paramsµÄ²ÎÊýÊý×é¡£
×ܽ᣺
ͨ¹ý×Ô½ç˵Ìøתº¯Êý£¬ÎÒÃÇ¿ÉÒÔʵÏÖ¸üÎÞа¡¢¸ü¾«×¼µÄÌøת¡£µ±ÏµÍ³×Ô´øµÄÌøתº¯ÊýÎÞ·¨Öª×ãÎÒÃǵÄÐèÇóʱ£¬ÎÒÃÇ¿ÉÒÔƾ֤ÉÏÃæµÄÒªÁì¾ÙÐÐ×Ô½ç˵Ìøתº¯ÊýµÄ±àд¡£
ÒÔÉϾÍÊÇthinkphp×Ô½ç˵ÌøתµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡