使用 PHP 更改用户代理

发布于 2024-12-28 15:21:32 字数 280 浏览 3 评论 0原文

我的服务器上有一个应用程序,它会重定向到 Facebook,从而显示 Facebook 登录页面的浏览器版本。

但是,由于我将通过移动设备访问它,因此我希望它显示 Facebook 登录页面的移动版本。

是否可以使用 header() 函数,或者是否有办法在重定向到 Facebook 之前更改主机上的用户代理?这样 Facebook 就会认为请求来自移动设备,从而呈现移动版本。

我已经尝试过使用 JavaScript 并尝试欺骗 header 命令;不幸的是这些没有用。

谢谢。

I have an app on my server which redirects to Facebook and thus displays the browser version of the Facebook Login page.

However, since I'll be accessing this through a mobile device, I'll want it to display the mobile version of the Facebook login page.

Is it possible to use the header() function or is there a way to change the user-agent on my host before it redirects to Facebook? So that Facebook will think the request is coming from a mobile device and thus render the mobile version.

I have already tried to use JavaScript and tried spoofing the header command; unfortunately these didn't work.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀞厅☆埖开 2025-01-04 15:21:32
ini_set('user_agent', 'MyBrowser v42.0.4711');
ini_set('user_agent', 'MyBrowser v42.0.4711');
吝吻 2025-01-04 15:21:32

您的服务器不能影响远程浏览器的配置。唯一可以更改用户代理的地方是如果您将浏览器的请求代理到 facebook,因为连接到 FB 的是您的服务器,而不是客户端。

尝试重定向到 m.facebook.com。这显示了最小的“移动”版本。

Your server cannot affect the remote browser's configuration. The only place where you could change the user agent is if you were proxying the browser's requests to facebook, as it'd be your server connecting to FB, not the client.

Try redirecting to m.facebook.com instead. That displays a minimal "mobile" version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文