Change User-Agent Using PHP

2019-05-24 14:51发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-05-24 15:30
ini_set('user_agent', 'MyBrowser v42.0.4711');
查看更多
3楼-- · 2019-05-24 15:36

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.

查看更多
登录 后发表回答