Rectangle 27 1

function getBrowser() 
{ 
    $u_agent = $_SERVER['HTTP_USER_AGENT']; 
    $bname = 'Unknown';
    $platform = 'Unknown';
    $version= "";

    //First get the platform?
    if (preg_match('/linux/i', $u_agent)) {
        $platform = 'linux';
    }
    elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
        $platform = 'mac';
    }
    elseif (preg_match('/windows|win32/i', $u_agent)) {
        $platform = 'windows';
    }

    // Next get the name of the useragent yes seperately and for good reason
    if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) 
    { 
        $bname = 'Internet Explorer'; 
        $ub = "MSIE"; 
    } 
    elseif(preg_match('/Firefox/i',$u_agent)) 
    { 
        $bname = 'Mozilla Firefox'; 
        $ub = "Firefox"; 
    } 
    elseif(preg_match('/Chrome/i',$u_agent)) 
    { 
        $bname = 'Google Chrome'; 
        $ub = "Chrome"; 
    } 
    elseif(preg_match('/Safari/i',$u_agent)) 
    { 
        $bname = 'Apple Safari'; 
        $ub = "Safari"; 
    } 
    elseif(preg_match('/Opera/i',$u_agent)) 
    { 
        $bname = 'Opera'; 
        $ub = "Opera"; 
    } 
    elseif(preg_match('/Netscape/i',$u_agent)) 
    { 
        $bname = 'Netscape'; 
        $ub = "Netscape"; 
    } 

    // finally get the correct version number
    $known = array('Version', $ub, 'other');
    $pattern = '#(?<browser>' . join('|', $known) .
    ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
    if (!preg_match_all($pattern, $u_agent, $matches)) {
        // we have no matching number just continue
    }

    // see how many we have
    $i = count($matches['browser']);
    if ($i != 1) {
        //we will have two since we are not using 'other' argument yet
        //see if version is before or after the name
        if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
            $version= $matches['version'][0];
        }
        else {
            $version= $matches['version'][1];
        }
    }
    else {
        $version= $matches['version'][0];
    }

    // check if we have a number
    if ($version==null || $version=="") {$version="?";}

    return array(
        'userAgent' => $u_agent,
        'name'      => $bname,
        'version'   => $version,
        'platform'  => $platform,
        'pattern'    => $pattern
    );
} 

// now try it
$ua=getBrowser();
$yourbrowser= "Your browser: " . $ua['name'] . " " . $ua['version'] . " on " .$ua['platform'] . " reports: <br >" . $ua['userAgent'];
print_r($yourbrowser);
?>

This seems to work pretty well. Thank you. I did have issues with the named groups in the regexes (we must be using different versions of PHP); using non-named groups fixed the problem.

user agent - Is there a PHP library or script that converts a UA to a ...

php user-agent
Rectangle 27 71

I actually figured this out myself. I had the !DOCTYPE html tag wrongly written. So if you have this problem make sure the doctype declaration is correct! share|improve this answer edited Sep 1 '16 at 18:49 gunr2171 6,401103862 answered Mar 11 '12 at 16:08 Riku 1,1881918

Fix indeed. Still utterly confusing why it would do that

I had this problem when trying to convert haml files to erb format (ruby on rails). Haml auto-includes a doctype with the notation !!!.

@Riku Wonderful fix.Thanks a lot dude. Had been breaking my head for 2 hours ! .. But weird bug .

Yes, make sure <!DOCTYPE html> appears at the top of your HTML.

user agent stylesheet
table
<!DOCTYPE html>
:)

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

css - User agent stylesheet overriding my table style? Twitter Bootstr...

css twitter-bootstrap
Rectangle 27 1

For some reason my user agent was incorrect. I believe it may have been because I previously invoked the Firebug Lite bookmarklet. The correct user agent is:

(window.navigator.userAgent.indexOf('Android') > -1 && (/Chrome\/[.0-9]*/).test(window.navigator.userAgent)) || navigator.userAgent.match('CriOS');

jquery - Detect Chrome iPhone 6+ - Stack Overflow

jquery ios user-agent detect iphone-6-plus
Rectangle 27 1

For some reason my user agent was incorrect. I believe it may have been because I previously invoked the Firebug Lite bookmarklet. The correct user agent is:

(window.navigator.userAgent.indexOf('Android') > -1 && (/Chrome\/[.0-9]*/).test(window.navigator.userAgent)) || navigator.userAgent.match('CriOS');

jquery - Detect Chrome iPhone 6+ - Stack Overflow

jquery ios user-agent detect iphone-6-plus
Rectangle 27 7

Including the cordova.js script in the remote site is going to be tricky, because there's a different cordova.js for each platform. You could modify the server so that it returns the correct cordova.js based on the user agent, but this is also tricky because it will include this script when you view the site from a mobile browser, and this is undesirable because javascript errors might be shown to the user. Same story when viewing the site from a desktop computer, the cordova.js should not be included.

It looks to me that you have a local web page (with the cordova script included) and from there you change to the remote page (that also includes the script). I'm not sure this page change is going to work. If it worked, you might have to wait for the second deviceready event.

But you can just set the remote site page as the root page in the cordova app, no need for an intermediate "loader" page. Just set it in the config.xml file:

<content src="http://your.website.fake/index.html" />

You need to make sure that you allow loading your site in the app. In this same file, you should add:

<access origin="http://your.website.fake" subdomains="true"/>

I've tried it already, this way you are able to load the remote page, but not able to access the phongap api

What API are you using? If you are trying to use a third party plugin, AND provided you have included the plugin script in the site as well, it should work.

I'm using the built in camera plugin. It doesn't work. The only workaround I've found is to load the remote page in an IFrame inside a local page. And use js postMessage to communicate between them. Yet this solution is inconvenient and causes other issues (Same origin etc).

I've double checked that everything configured correct, and the same configuration and code works fine in local page. It looks like it is intentionally blocked by Cordova, as suggested by Rivera below. Yet, loading the remote page with Ajax sounds like something that could work, you should have started with that :) I'll try and update, thanks a lot!

@AliNaciErdem: The iframe method works just fine. but it causes other issues. see details here MisterSmith, I think i'll skip phonegap for my current project and simply use a JS interface that built in Android. I know it works with remote pages for sure.

javascript - How to get access to phonegap API from a remote page - St...

javascript android ios cordova cordova-plugins
Rectangle 27 3

As you point out, 403 Forbidden is explicitly defined with the phrase "Authorization will not help", but it is worth noting that the authors were almost certainly referring here to HTTP authorization (which will indeed not help as your site uses a different authorization scheme). Indeed, given that the status code is a signal to the user agent rather than the user, such a code would be correct insofar as any authorization the agent attempts to provide will not assist any further with the required authorization process (c.f. 401 Unauthorized).

However, if you take that definition of 403 Forbidden literally and feel it is still inappropriate, perhaps 409 Conflict might apply? As defined in RFC 2616 10.4.10:

There is indeed a conflict with the current state of the resource: the resource is in a "locked" state and such conflict can only be "resolved" through the user providing their credentials and resubmitting the request. The body will include "enough information for the user to recognize the source of the conflict" (it will state that they are not logged-in) and indeed will also include "enough information for the user or user agent to fix the problem" (i.e. a login form).

rest - Correct http status code for resource which requires authorizat...

rest http-status-codes
Rectangle 27 3

As you point out, 403 Forbidden is explicitly defined with the phrase "Authorization will not help", but it is worth noting that the authors were almost certainly referring here to HTTP authorization (which will indeed not help as your site uses a different authorization scheme). Indeed, given that the status code is a signal to the user agent rather than the user, such a code would be correct insofar as any authorization the agent attempts to provide will not assist any further with the required authorization process (c.f. 401 Unauthorized).

However, if you take that definition of 403 Forbidden literally and feel it is still inappropriate, perhaps 409 Conflict might apply? As defined in RFC 2616 10.4.10:

There is indeed a conflict with the current state of the resource: the resource is in a "locked" state and such conflict can only be "resolved" through the user providing their credentials and resubmitting the request. The body will include "enough information for the user to recognize the source of the conflict" (it will state that they are not logged-in) and indeed will also include "enough information for the user or user agent to fix the problem" (i.e. a login form).

rest - Correct http status code for resource which requires authorizat...

rest http-status-codes
Rectangle 27 1

The headers are correct and there's nothing wrong with them or your application. For historic reasons they contain a lot data and can't be easily changed to be compatible with old web applications.

That's one of the funniest blog posts I've read for a long time.

Spring Java servlet return incorrect user agent - Stack Overflow

java spring google-chrome firefox servlets
Rectangle 27 2

This may not be the perfect solution, but there are iPhone-only browsers that will work on the iPad in iPhone-mode. For instance, the free Mango Browser works well, and seems to present the correct User Agent to sites, so you'll get a fairly good feel for what the experience will be like. I just tested it on a few sites, and it renders the same as on my iPhone using Safari.

Although not an exact implementation, this seems to be the best solution as of now. Thanks for your response.

iPhone Safari testing on iPad? - Stack Overflow

iphone ipad safari mobile-safari
Rectangle 27 1

With IE11 RTM those lists are populated from a service, when that fails the lists are empty :(. With the April update to IE11 the fall back should be a default list of entries rather than blank. Try installing the latest Windows Update.

I am running 11.0.9600.17105 which is the latest version I think.

internet explorer - IE11 developer tools - document mode and user agen...

internet-explorer internet-explorer-11
Rectangle 27 3

At NPR, we use a server side 'application' to serve up the correct html/css/etc depending on if the user is on a high-end device or a lower-tier phone.

So, when a mobile device pings an npr.org page, our servers use a user-agent detection method to point them to the corresponding m.npr.org. Once directed to the m.npr.org URL, the web app - which is written in groovy, but I think could potentially be a number of things - sends back either the touch version of the site or the more simple, stripped down content. The choice of the web app is made based at least somewhat on the WURFL data.

I don't have enough rep points to post a comparison with screenshots, so I'll have to point you to the sites themselves.

You can see this in your desktop browser by typing in m.npr.org to see the stripped down site. And you can override the default device detection by adding the parameter ?devicegate.client=iPhone_3_0 to see the touch version you would see if you just went to npr.org on your smartphone. If you view the source, you can see how different html & css is being served at the same subdomain.

Hope it helps seeing something like this in the wild. Does that make sense?

That totally helps. So, these are literally different 'apps' that are served based on the UA? Any advantage / disadvantage over the "different app views" method described by Johni here?

xhtml mp - Server-side options to deliver different page structure (HT...

mobile xhtml-mp
Rectangle 27 0

Solution for this problem is not sanding XHTML from server but native HTML. This providing filter which change response from application/xhtml+xml to text/html. Filter get response form header of user agent and find if is set compatible; msie 8.0 which means, that IE11 runs under Enterprise Mode and Emulate IE8.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

   String userAgent = ((HttpServletRequest) request).getHeader("user-agent");

   if (userAgent != null && userAgent.toLowerCase().contains("compatible; msie 8.0"))
    {   
     chain.doFilter(request, new ForcableContentTypeWrapper((HttpServletResponse) response));
    }
    else 
    {
     chain.doFilter(request, response);
    }
}

private class ForcableContentTypeWrapper extends HttpServletResponseWrapper
{
     public ForcableContentTypeWrapper(HttpServletResponse response)
    {
    super(response);
    }

    @Override
    public void setContentType(String type)
    {
      if (type.contains("application/xhtml+xml")) 
    {
        super.setContentType(type.replace("application/xhtml+xml", 
                                          "text/html"));
    }
    else 
    {
      super.setContentType(type);
    }

     }
 }

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

internet explorer - JSF application using IE11 with Enterprise Mode - ...

internet-explorer richfaces internet-explorer-11 jsf-1.2 netweaver
Rectangle 27 0

The "Browser Mode" from the old developer tools was limited to only Internet Explorer browsers. In the new Developer tools, you are able to Emulate User agent strings for all of the commonly used browsers.

Changing your user agent string is a good first step in debugging errors that are only happening in IE, but not in other browsers. It's basically a way of telling IE to identify itself as a different version or even another browser.

Front end and/or back end scripts sometimes try to detect which browser you're using. And even when you're not using browser detection in your own code, you may be using a third-party JavaScript library or server-side script that does.

The problem with browser detection is that it's often used to scale back or change the features in a webpage based on what the developer writing the script thinks your browser can do, rather than detecting what your browser can actually do using feature detection. This can cause unexpected behavior, because code targeted at Microsoft Internet Explorer 6 runs differently in IE11 Preview, or a feature your browser is perfectly capable of supporting might be disabled because of an assumption made by the developer.

The User agent string doesn't make the browser work any differently, but it does allow you much more testing ability than the old Browser Mode setting did. You now have the ability to test the Document Mode and User agent string independently of each other, instead of a forced Microsoft browsers only type test.

This Document Mode and User agent string independently was possible in IE since version 7. For same strange reason they called User Agent string "Document mode", and browser emulation was available under "Browser mode"

Eugene, you're confused: "Browser mode" controlled many things including the User-Agent string, while "Document mode" controlled which emulation was used when parsing/displaying HTML and running JavaScript.

ie developer tools - How to bring back "Browser mode" in IE11? - Stack...

cross-browser ie-developer-tools internet-explorer-11
Rectangle 27 0

This might sound odd, but it helps to check (especially if you aren't using an IDE or one that doesn't do validation on your CSS). You might want to make sure that you have a ; and not a : at the end of your:style; line. Because at a glance, in the inspector the syntax appears to be correct but isn't. So your user agent stylesheet overwrites it. It's one of those "make sure your printer is plugged in" checks. It happens to all of us every once in a while.

css - Why does user agent stylesheet override my styles? - Stack Overf...

css font-size
Rectangle 27 0

In IE11, F12 to access developer tools. Scroll down to the bottom, "Emulation" and set the "User Agent String" to Internet Explorer 10.

OMG you are a saviour....

internet explorer - remote desktop services activex client control IE ...

internet-explorer activex remote-desktop internet-explorer-11 browser-addons
Rectangle 27 0

It's probably a character encoding issue. simply means character number 128 from the ISO 10646 codepage, which is technically undefined. For historical reasons, most browsers map these characters according to windows-1252, but this is anything but standardized behavior. , however, unambiguously maps to the euro currency sign, regardless of character encoding. There is a third option: use the unicode code point for the euro sign (). This, too, should work in any browser. And finally, you can put a literal euro sign into the HTML, but if you do, you need to make sure you set the correct encoding in your content-type headers, so that the receiving user agent can make sense of it.

From your comment it is clear that there are issues with making blanket changes like this. Changing this value in my database will affect many parts of the system, so, understandibly, I am wary. It may be misunderstanding that is the reason is in the database, so from what you are saying changing to is the recommended course of action.

always means character 128 from ISO 10646, not from the currently selected code page.

By the specifications, means character with code number n in ISO 10646 and Unicode, independently of character encoding. This is technically undefined, because character 128 is a control character in Unicode and forbidden in HTML. In practice, browsers traditionally interpret such code numbers according to windows-1252, yielding the euro sign in this case. It is surprising if this does not happen in Gmail, but anyway, use a correct reference like .

JukkaK.Korpela & JoniSalonen: Good point, editing.

firefox - € HTML entity for Euro currency symbol not visible in ...

html firefox gmail html-entities html4
Rectangle 27 0

IMHO, if user agents make a request to your server about a domain that you are not serving, then a 404 (not found) seems the most logical to me. After all the domain (and any page associated with it) does not exist on (your) server.

I would serve the 404 and log the acccesses. If you receive a high number of requests for one domain, then maybe you could try notifying the owner of the domain name (if reachable).

Edit: If the problem is the host-name header being incorrect, then I think at least IIS will return a 400 (bad request) as a response, which might be an alternative in this case.

The 404 is my gut feeling too, but 200 is so common I wanted to ask around before doing that. Returning a 404 seems safer if I want to provide body text explaining the error in addition, do you know how most browsers handle a 400?

I'm with you to use a 404 in this case, so +1. But I disagree serving a 400, because this only should be used for malformed syntax. An unkown host name in proper headers is no malformed syntax to me.

Returning 200 is really bad, IMHO. It is a lie, after all. If I were a browser, I would like to receive a 404. ;-)

http - What is the correct way for a webserver to respond to a request...

http webserver virtualhost
Rectangle 27 0

The solution was that the user under which the SQL Server Agent was running needed to be logged-in to the windows. Else, the regional settings would not be correct. No idea why this is the case ... but it works correctly if user is logged in windows.

SSIS Script Task regional settings - Stack Overflow

ssis
Rectangle 27 0

Including the cordova.js script in the remote site is going to be tricky, because there's a different cordova.js for each platform. You could modify the server so that it returns the correct cordova.js based on the user agent, but this is also tricky because it will include this script when you view the site from a mobile browser, and this is undesirable because javascript errors might be shown to the user. Same story when viewing the site from a desktop computer, the cordova.js should not be included.

It looks to me that you have a local web page (with the cordova script included) and from there you change to the remote page (that also includes the script). I'm not sure this page change is going to work. If it worked, you might have to wait for the second deviceready event.

But you can just set the remote site page as the root page in the cordova app, no need for an intermediate "loader" page. Just set it in the config.xml file:

<content src="http://your.website.fake/index.html" />

You need to make sure that you allow loading your site in the app. In this same file, you should add:

<access origin="http://your.website.fake" subdomains="true"/>

I've tried it already, this way you are able to load the remote page, but not able to access the phongap api

What API are you using? If you are trying to use a third party plugin, AND provided you have included the plugin script in the site as well, it should work.

I'm using the built in camera plugin. It doesn't work. The only workaround I've found is to load the remote page in an IFrame inside a local page. And use js postMessage to communicate between them. Yet this solution is inconvenient and causes other issues (Same origin etc).

Could you please elaborate on the "doesn't work" part? Can you check using console log if cordova has been loaded, and whether the camera object is defined? Try this with the xml config I posted, the hot page-change you are attempting sounds like the kind of thing that doesn't work well.

@AliNaciErdem: The iframe method works just fine. but it causes other issues. see details here MisterSmith, I think i'll skip phonegap for my current project and simply use a JS interface that built in Android. I know it works with remote pages for sure.

javascript - How to get access to phonegap API from a remote page - St...

javascript android ios cordova cordova-plugins
Rectangle 27 0

Flash can give you a list of fonts on the user's machine among other things. Javascript can send information when the mouse stops over an ad without clicking it. You can also get the window size, whether the site is open in a frame, if popups or specific plugins have been blocked, looking for Javascript features can tell if the user agent header is correct or faked...

security - What identifying information can a website capture? - Stack...

security browser