创建代理以欺骗PHP中的iPhone用户代理? [英] Creating a proxy to spoof iPhone user-agent in PHP?

查看:129
本文介绍了创建代理以欺骗PHP中的iPhone用户代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基于网络的iPhone模拟器,我正在寻找一种方法来欺骗iPhone的Safari浏览器,以便在模拟器(iframe)中加载的网页使用移动版本。根据我的理解,我需要修改用户代理。

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 mobile versions. From my understanding I need to modify the user-agent.

如何创建PHP代理脚本以欺骗iPhone的用户代理?

How do I go about creating a PHP proxy script to spoof the iPhone's user-agent?

推荐答案

您可以使用像cURL这样的库来请求带有iPhone用户代理的页面,并将该页面返回到您的站点(请务必扩展相对使用DOMDocument的绝对URL。

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).

但是,您可能遇到通过用户代理以不同方式提供CSS / JavaScript /图像的边缘情况。这可能不值得为这些机会申请这些资产。您可以通过向用户代理请求一次,然后使用iPhone用户代理,执行 md5_file()并查看它们是否不同来限制工作。我不会打扰:P

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

你也可以尝试这个JavaScript ......

You could also try this JavaScript...

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

navigator.userAgent; // 'foo'

来源

另外请记住,如果您的用户不在,您可能需要发出警告使用Safari,它最接近模拟Mobile Safari。

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.

这篇关于创建代理以欺骗PHP中的iPhone用户代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆