Change user agent

Asked

Viewed 245 times

0

I need to change the user agent on mobile. I tried with pure php but it didn’t work, I’m using Mobile Detect, I can even detect when it’s mobile, but I can’t change the user agent.

The example I followed was this

if(!$detect->isMobile()) {    
    $userAgent = 'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103';    
    $detect->setUserAgent($userAgent);    
    echo $_SERVER['HTTP_USER_AGENT'] . "<hr />\n";
}

What is wrong?

1 answer

1

The user-agent is what the client informs. If the client informs a different user-agent than it actually is, the server has no way of knowing.

That being said, the $_SERVER['HTTP_USER_AGENT'] is set at the moment the server receives the request. Even with the change, the variable is already defined (with the old value).

Try

$_SERVER['HTTP_USER_AGENT'] = 'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103';
  • It worked out Victor, but he still doesn’t bring the whole desktop version. What should I do? Record a cookie, a session and reload the page? I need to mimic the same "Request desktop site" function in Chrome for mobile. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64) Applewebkit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.