Change user agent

0

I need to change the user agent on mobile. I tried with pure php but it did not work, I'm using Mobile Detect, until I can detect when it's mobile, but I can not 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's wrong?

    
asked by anonymous 18.01.2018 / 15:32

1 answer

1

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

That said, $ _SERVER ['HTTP_USER_AGENT'] is set 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';
    
18.01.2018 / 15:47