Creating a proxy to spoof iPhone user-agent in PHP?

后端 未结 3 1395
别跟我提以往
别跟我提以往 2020-12-17 04:52

I\'m writing a web based iPhone simulator and I\'m looking for a way to spoof iPhone\'s Safari browser so that web pages loaded within the simulator (iframe) to use the mobi

3条回答
  •  情书的邮戳
    2020-12-17 05:34

    You could use a library like cURL to request the page with the iPhone user agent, and return that page to your site (be sure to expand relative URLs to absolute, with DOMDocument).

    However, you may run into edge cases where CSS/JavaScript/images are served differently via the user agent. This is probably not worth requesting each of these assets on the off chance. You could limit the work by requesting once with your user agent, and then the iPhone user agent, doing md5_file() and seeing if they are different. I wouldn't bother though :P

    You could also try this JavaScript...

    navigator.__defineGetter__('userAgent', function(){
        return 'foo' // customized user agent
    });
    
    navigator.userAgent; // 'foo'
    

    Source.

    Also remember you may want to give a warning if your users aren't using Safari, which will be the closest to simulate Mobile Safari.

提交回复
热议问题