ÔÚThinkPHPÖÐÔõôʵÏÖURLÖÐÎÄתÂë
ÔÚURLÖÐʹÓÃÖÐÎÄ×Ö·ûÊǺܳ£¼ûµÄÐèÇó£¬ÀýÈçÔÚÂÛ̳ÖУ¬Ìû×ÓµÄÎÊÌâ¾³£ÊÇÖÐÎĵģ¬ÐèÒª½«Æä×÷ΪURLµÄÒ»²¿·ÖÀ´ÌìÉúÒ³ÃæµØµã¡£¿ÉÊÇ£¬ÓÉÓÚÀúÊ·Ôµ¹ÊÔÓɺÍÐÒéÏÞÖÆ£¬URLÖ»ÄÜʹÓÃASCIIÂë±íÖб£´æµÄ×Ö·û¡£ÎªÁËÄܹ»Ê¹ÓÃÖÐÎÄ×Ö·ûÌìÉúURLµØµã£¬ÎÒÃÇÐèÒªÒ»ÖÖÒªÁ콫ÕâЩ×Ö·ûת»»³ÉÇå¾²µÄURL×Ö·û¡£
Ò»ÖÖ³£¼ûµÄתÂëÒªÁìÊÇʹÓÃurlencodeº¯Êý¡£´Ëº¯ÊýµÄ×÷ÓÃÊǽ«ÖÐÎÄ×Ö·ûת»»ÎªÌØÊâµÄÊ®Áù½øÖƱàÂ룬ÒÔ×èÖ¹ÔÚURLÖÐÔì³É³åÍ»¡£ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃurlº¯Êý¾ÙÐÐURL±àÂë¡£ÀýÈ磺
$url = url('/index/index', ['title' => urlencode('ÖÐÎÄÄÚÈÝ')]);
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«ÖÐÎÄÄÚÈÝת»»Îªurlencode±àÂ룬²¢½«Æä×÷Ϊtitle²ÎÊýת´ï¸øÁËÎÒÃǵĿØÖÆÆ÷ÒªÁì¡£ÔÚ¿ØÖÆÆ÷µÄÒªÁìÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃurldecodeº¯ÊýÀ´»¹Ô±»×ªÂëµÄÖÐÎÄ×Ö·û¡£ÀýÈ磺
public function index($title) { $title = urldecode($title); // ... }
µÇ¼ºó¸´ÖÆ
ÕâÖÖÒªÁìÊÇ¿ÉÐеģ¬µ«ËüÓÐÒ»¸öÏÔÖøµÄÈõµã£¬¾ÍÊÇÊ®Áù½øÖƱàÂëºóµÄ×Ö·û¹´Í¨³£±ÈÔʼµÄÖÐÎÄ×Ö·û´®Òª³¤Ðí¶à£¬Õâ»áµ¼ÖÂURL±äµÃºÜÊÇòÇÞºÍÄÑÒÔÓ°Ïó¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÖÐÎÄ×Ö·ûµÄURL±àÂë¿ÉÒÔͨ¹ýʹÓÃURLÇå¾²µÄBase64±àÂëÀ´ÊµÏÖ£¬´Ó¶ø½â¾ö¸ÃÎÊÌâ¡£ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃbase64url_encodeºÍbase64url_decodeº¯Êý¡£ÀýÈ磺
$url = url('/index/index', ['title' => base64url_encode('ÖÐÎÄÄÚÈÝ')]);
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«ÖÐÎÄÄÚÈÝʹÓÃURLÇå¾²µÄBase64±àÂ룬²¢½«Æä×÷Ϊtitle²ÎÊýת´ï¸øÁËÎÒÃǵĿØÖÆÆ÷ÒªÁì¡£ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÒªÁìÖÐʹÓÃbase64url_decodeº¯Êý½«Æä½âÂë³ÉÔʼµÄÖÐÎÄ×Ö·û¡£ÀýÈ磺
public function index($title) { $title = base64url_decode($title); // ... }
µÇ¼ºó¸´ÖÆ
ʹÓÃBase64±àÂëµÄÒªÁìÏà±ÈÓÚurlencodeÒªÁìÓÐÒ»¸öÏÔ×ŵÄÓŵ㣬ÄǾÍÊÇËüÌìÉúµÄ±àÂë×Ö·û´®Ïà¶Ô½Ï¶Ì£¬Ô½·¢ÑŹۡ¢Ò׶Á¡£µ«ÐèҪעÖصÄÊÇ£¬ÕâÖÖÒªÁìÔÚÌìÉúURLÇå¾²×Ö·û´®Ê±£¬ÐèҪʹÓÃһЩÌØÊâµÄ×Ö·ûÌæ»»ÔʼµÄBase64×Ö·û£¬ÀýÈ罫·ûºÅ+Ì滻Ϊ-£¬½«·ûºÅ/Ì滻Ϊ_£¬²¢È¥µô×îºó¿ÉÄÜ·ºÆðµÄ=·ûºÅ¡£
ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóÑ¡ÔñºÏÊʵÄתÂëÒªÁì¡£ÎÞÂÛÊÇurlencodeÕÕ¾ÉBase64±àÂ룬ÎÒÃǶ¼ÐèҪעÖØÌìÉúµÄURLÊÇ·ñÇкϹ淶£¬²¢ÇÒÔÚ¿ØÖÆÆ÷ÒªÁìÖоÙÐÐ׼ȷµÄ½âÂë´¦Àí£¬ÒÔ°ü¹ÜÎÒÃǵÄÓ¦ÓÃÄܹ»Õý³£´¦ÀíÖÐÎÄ×Ö·ûµÄURL¡£
ÒÔÉϾÍÊÇÔÚThinkPHPÖÐÔõôʵÏÖURLÖÐÎÄתÂëµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡