thinkphp3.2ÔõôÅäÊÖ»úÕ¾ÓòÃû
Ëæ×ÅÒƶ¯»¥ÁªÍøµÄÐËÆð£¬Ô½À´Ô½¶àµÄÍøÕ¾×îÏȹØ×¢ÊÖ»úÕ¾µÄ½¨Éè¡£¶ø¹ØÓÚÓÃthinkphp3.2¿ò¼Ü´î½¨µÄÍøÕ¾£¬ÔõÑù¾ÙÐÐÊÖ»úÕ¾µÄÓòÃûÉèÖÃÄØ£¿½ÓÏÂÀ´£¬±¾ÎĽ«Îª¸÷ÈËÏêϸÏÈÈÝthinkphp3.2ÔõÑùÅäÊÖ»úÕ¾ÓòÃû¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÃ÷È·Ò»¸ö¿´·¨£ºÊÖ»úÕ¾ºÍPCÕ¾ÊÇÁ½¸ö×ÔÁ¦µÄÍøÕ¾£¬ËüÃǵÄÒ³Ãæ¡¢Á´½Ó¡¢×ÊÔ´µÈ¶¼ÊǸ÷×Ô×ÔÁ¦µÄ¡£Òò´Ë£¬¹ØÓÚthinkphp3.2¿ò¼ÜÀ´Ëµ£¬ÊÖ»úÕ¾Ò²ÐèÒª×ÔÁ¦ÉèÖÃÓòÃû¡£
»ñÈ¡ÊÖ»úÕ¾ÓòÃû
Ê×ÏÈ£¬ÎÒÃÇÐèÒª»ñÈ¡Ò»¸öÊÖ»úÕ¾µÄÓòÃû¡£¿ÉÒÔÔÚº£ÄÚµÄһЩÓòÃû×¢²áÉ̾ÙÐйºÖã¬Ò²¿ÉÒÔÔÚÍâÑóµÄһЩע²áÉ̾ÙÐйºÖᣲ»¹ÜÊǺ£ÄÚÕÕ¾ÉÍâÑ󣬶¼ÐèҪѡÔñÒ»¸öÎȹ̵Ä×¢²áÉÌ£¬ÒÔÈ·±£ÓòÃûµÄ¿ÉÓÃÐÔºÍÎȹÌÐÔ¡£±ðµÄ£¬ÎÒÃÇ»¹ÐèҪƾ֤ÊÖ»úÕ¾µÄÏÖÕæÏàÐÎÑ¡Ôñ²î±ðµÄÓòÃûºó׺£¬ÀýÈç.com¡¢.cn¡¢.netµÈ¡£
ÉèÖÃÊÖ»úÕ¾µÄ¸ùĿ¼
»ñÈ¡ÁËÊÖ»úÕ¾ÓòÃûºó£¬ÎÒÃÇÐèÒªÔÚÍøÕ¾¸ùĿ¼ÏÂн¨Ò»¸öĿ¼£¬²¢½«ÊÖ»úÕ¾µÄÒ³Ãæ¡¢Á´½Ó¡¢×ÊÔ´µÈ°²ÅÅÔÚ¸ÃĿ¼Ï¡£ÐèҪעÖصÄÊÇ£¬ÊÖ»úÕ¾µÄĿ¼½á¹¹ºÍÍøÕ¾µÄĿ¼½á¹¹ÊÇÏ໥×ÔÁ¦µÄ£¬²»ÒªÓëÍøÕ¾µÄÎļþ»ìÏý¡£
ͨ¹ýURLÖض¨ÏòʵÏÖ»á¼ûÊÖ»úÕ¾
ÓÐÁËÊÖ»úÕ¾µÄÓòÃûºÍ¸ùĿ¼ºó£¬ÎÒÃÇÐèÒª¶ÔÍøÕ¾¾ÙÐÐÉèÖã¬ÈÃÓû§ÔÚ»á¼ûÍøվʱÄܹ»Ö±½ÓÌøתµ½ÊÖ»úÕ¾¡£ÎÒÃÇ¿ÉÒÔͨ¹ýURLÖض¨ÏòµÄ·½·¨ÊµÏÖÕâһĿµÄ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚthinkphp3.2¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ýÔÚÈë¿ÚÎļþÖÐÉèÖÃÏà¹Ø´úÂëʵÏÖURLÖض¨Ïò£¬Ê¾Àý´úÂëÈçÏ£º
//ÅжÏÊÇ·ñÊÇÒƶ¯×°±¸»á¼û if (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false) { //Ìøתµ½ÊÖ»úÕ¾ header('Location:http://m.example.com'); exit; }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÊ×ÏÈɨÃè»á¼ûÍøÕ¾µÄ×°±¸ÀàÐÍ£¬ÈôÊÇÊÇÒƶ¯×°±¸£¬Ôò½«Óû§Öض¨Ïòµ½ÊÖ»úÕ¾µÄÓòÃûÏ¡£ÕâÑù£¬Óû§ÔÚ»á¼ûÍøվʱ£¬¾Í»áÖ±½ÓÌøתµ½ÊÖ»úÕ¾£¬ÊµÏÖ¿ì½Ý»á¼û¡£
ÉèÖÃÊÖ»úÕ¾µÄÈ«Õ¾SSLÖ¤Êé
¹ØÓÚÊÖ»úÕ¾À´Ëµ£¬ÎªÁË°ü¹ÜÓû§µÄÐÅÏ¢Çå¾²£¬ÎÒÃÇÐèҪΪÊÖ»úÕ¾ÉèÖÃÈ«Õ¾SSLÖ¤Ê顣ͨ¹ýSSLÖ¤ÊéµÄ¼ÓÃÜÊÖÒÕ£¬¿ÉÒÔ°ü¹ÜÓû§ÔÚÊÖ»úÕ¾»á¼ûµÄÐÅÏ¢²»±»ºÚ¿ÍÇÔÈ¡»òЮÖÆ¡£Òò´Ë£¬ÉèÖÃÈ«Õ¾SSLÖ¤ÊéºÜÊÇÖ÷Òª¡£
ÔÚthinkphp3.2¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ý»ñÈ¡SSLÖ¤ÊéºÍ˽ԿÎļþµÄ·½·¨À´ÊµÏÖSSLÉèÖá£Ê¾Àý´úÂëÈçÏ£º
//»ñÈ¡SSLÖ¤ÊéºÍ˽ԿÎļþ $certfile = 'ssl/xxxx.crt';//Ö¤ÊéÎļþ·¾¶ $keyfile = 'ssl/xxxx.key'; //˽ԿÎļþ·¾¶ //ʹÓÃSSLÖ¤ÊéºÍ˽ԿÎļþ $opts = array( 'ssl' => array( 'local_cert' => $certfile, 'local_pk' => $keyfile, ), ); //½á¹¹Context stream context $context = stream_context_create($opts);
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÊ×ÏÈ»ñÈ¡SSLÖ¤ÊéºÍ˽ԿÎļþµÄ·¾¶£¬È»ºóʹÓÃÕâÁ½¸öÎļþʵÀý»¯Ò»¸östream context¹¤¾ß£¬×îºóʹÓøù¤¾ßʵÏÖSSLÉèÖá£
×ܽá
ͨ¹ýÉÏÊö°ì·¨£¬ÎÒÃÇ¿ÉÒÔ½«thinkphp3.2¿ò¼ÜÖеÄÍøÕ¾ºÍÊÖ»úվʵÏÖ×ÔÁ¦ÓòÃûµÄ»á¼û¡£ÕâÑù£¬Óû§ÔÚ»á¼ûÍøվʱ£¬¿ÉÒÔƾ֤²î±ðµÄ×°±¸ÀàÐÍ×Ô¶¯Ìøתµ½ÏìÓ¦µÄÕ¾µã£¬Ìá¸ßÁËÓû§µÄ»áÊÕЧÂʺÍʹÓÃÌåÑ顣ͬʱ£¬Í¨¹ýÉèÖÃÈ«Õ¾SSLÖ¤Ê飬¿ÉÒÔ°ü¹ÜÓû§ÐÅÏ¢µÄÇå¾²ÐÔ£¬Ìá¸ßÁËÍøÕ¾µÄÇå¾²ÐÔ¡£
ÒÔÉϾÍÊÇthinkphp3.2ÔõôÅäÊÖ»úÕ¾ÓòÃûµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡