使用 PHP,在重定向之前编辑或更改用户代理?
我将流量重定向到另一个网站,但他们进行了一些过滤,拒绝了部分流量。据我了解,他们正在解析用户代理字符串并拒绝某些浏览器。我希望能够首先过滤我这边的 UA,并在重定向它们之前根据需要替换它们。
到目前为止我已经尝试过这个:
ini_set('user_agent', "my user agent");
但当重定向发生时它似乎并没有真正改变任何东西。
甚至可以这样做吗?由于 UA 是在浏览器中设置的,这是否更像是 Javascript 的事情?
我很欣赏任何想法...谢谢!
I'm redirecting traffic to another website, but they have some filtering in place that is rejecting a portion of the traffic. From what I understand, they're parsing the user agent string and refusing certain browsers. I'd like to be able to filter the UAs on my side first and replace them as needed before redirecting them.
So far I have tried this:
ini_set('user_agent', "my user agent");
but it doesn't seem to actually change anything when the redirection occurs.
Is it possible to even do this? Is it more of a Javascript thing since the UA is set in the browser?
I appreciate any ideas... thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
重定向不是这样工作的。远程服务器仍将从客户端计算机获取用户代理。如果您的服务器发出 cURL 请求,则设置您自己的用户代理将适用 - 然后它充当客户端。
That's not how redirects work. The remote server will still get the user agent from the client's machine. Setting your own user agent would be applicable if your server was making a cURL request - then it is acting as the client.
您无法从 php 脚本影响浏览器的用户代理设置。我也怀疑是否可以使用 JavaScript。但是,您可以做的是设置一个代理 php 脚本,该脚本执行从您的服务器到远程站点的请求,并根据您已经尝试过的内容(使用 ini_set)设置脚本的用户代理。
You cannot influence a browser's user agent setting from within a php script. I also doubt, that it is possible using JavaScript. However, what you might do is set up a proxy php script, which performs the requests to the remote site from your server and set the user agent of your script according to what you already tried (using ini_set).
另一个网站可能正在解析用户浏览器提交的标头。
因此无法更改用户代理
the other website is probably parsing the header which the users browser is submitting.
therefore it isn't posible to change the user agent