問題描述
我正在用 PHP 編寫一個網站.由于網絡上的任何人都需要訪問它才能訪問互聯網,因此我必須創建一個移動版本.我如何最好地檢查它是否是移動設備?我不想在最后有 50 個設備的 switch 語句,因為我不僅想支持 iPhone.
I am writing a website with PHP. Since it will need to be accessed by anyone on the network to access the internet I have to create a mobile version. How do I best check if it's a mobile device? I don't want to have a switch statement with 50 devices at the end since I don't only want to support the iPhone.
有我可以使用的 PHP 類嗎?
Is there a PHP class I could use?
推薦答案
您需要檢查客戶端發送的幾個標頭,例如 USER_AGENT 和 HTTP_ACCEPT.查看這篇文章,了解針對移動用戶代理的綜合檢測腳本PHP.
You need to check several headers that the client sends, such as USER_AGENT and HTTP_ACCEPT. Check out this article for a comprehensive detection script for mobile user-agents in PHP.
這篇關于如何確定它是否是帶有 PHP 的移動設備?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!