Change User-Agent Using PHP

时光怂恿深爱的人放手 提交于 2019-12-07 23:46:11

问题


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.


回答1:


ini_set('user_agent', 'MyBrowser v42.0.4711');



回答2:


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.



来源:https://stackoverflow.com/questions/8974742/change-user-agent-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!