Opera 中的欺骗 UserAgent
我试图将 Opera(在 Linux 下)伪装成另一个浏览器,在本例中是 iPad,用于某些测试目的。 现在我知道网站可以检查哪个浏览器正在访问它,例如在 PHP $useragent = $_SERVER['HTTP_USER_AGENT'];
和 JavaScript navigator.userAgent
中(或navigator.platform
)。
在 Firefox 中,您可以使用插件轻松切换用户代理和其他相关信息,但在 Opera 中似乎有点难做到。
首先在 opera.ini
中您可以执行以下操作:
[User Agent]
Spoof UserAgent ID=1
但这仅限于预定义的 UserAgent 列表。没有空间容纳定制的。
同样在 opera.ini
中
[ISP]
Id=iPad
这会将 iPad 添加到 Opera 的用户代理中。这是一个开始,大部分时间都可以在网站上运行。
在 opera.ini
中,您可以设置“用户 JavaScript 文件”以在加载网站之前加载自定义 JavaScript 文件:
[User Prefs]
User JavaScript File=/opera_dir/userjs/load.js
在 load.js
中,您可以执行以下操作:
navigator.userAgent = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10"
因为此文件获取在加载网站之前执行我可以修改 UserAgent,但是当站点通过 PHP 检查 UserAgent 时这将不起作用,但它适用于使用 JavaScript 检查的站点。
是否有另一种方法来欺骗完整的自定义 UserAgent?
I'm trying to spoof Opera (under Linux) to be another browser, in this case iPad for some testing purposes.
Now I know sites can check which browser is accessing it using, for example, in PHP $useragent = $_SERVER['HTTP_USER_AGENT'];
and in JavaScript navigator.userAgent
(or navigator.platform
).
In Firefox you can use an addon to easily switch your user agent and other relevant information, but in Opera it seems it bit hard to do.
First in opera.ini
you can do:
[User Agent]
Spoof UserAgent ID=1
But this is limited to a predefined list of UserAgents. No room for custom ones.
Also in opera.ini
[ISP]
Id=iPad
This will add iPad to the User Agent of Opera. It's a start and works most of the time on the sites.
In opera.ini
you can set a 'User JavaScript file' to load a custom JavaScript file before loading a website:
[User Prefs]
User JavaScript File=/opera_dir/userjs/load.js
In load.js
you can do:
navigator.userAgent = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10"
Because this file gets executed before loading the website I can modify the UserAgent, but this won't work when a site is checking the UserAgent via PHP, but it works for sites checking with JavaScript.
Is there another way of spoofing a complete custom UserAgent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能。在桌面 Opera 中,就是这样。
http://labs.opera.com 上找到的一些自定义(“GOGI”类型)开发人员版本可能会提供opera:config#UserPrefs|CustomUser-Agent 选项,您可以在其中指定整个 UA 字符串(不久前发布的版本现在已经相当旧了)。也许您更适合使用设备 SDK 工具?看看 http://dev.opera.com/sdk/
You can't. In desktop Opera, that is.
Some custom ("GOGI"-type) developer builds found on http://labs.opera.com might offer the opera:config#UserPrefs|CustomUser-Agent option where you can specify the entire UA string (the builds that were released a while back are rather old by now). Perhaps you'd be better of with the device SDK tools? Have a look at http://dev.opera.com/sdk/
您可以使用网络代理完成同样的任务。我会推荐尝试一下
Charles Web 调试代理。来自charles proxy的介绍:
You can accomplish the same feat using a web-proxy. I'll recommend to try out
Charles Web Debugging Proxy. From the charles proxy introduction: