Accurate, high-speed UA recognition in PHP

Source: Internet
Author: User
Fast and accurate UA recognition in PHP

Ua:user-agent This can be obtained in the server variables provided by PHP. What is the purpose of user-agent recognition?

1. What browser is it? This is no longer necessary. CSS hack can help you render correctly by browser.

2, Browser type: This is sure to, we most want to know that it is in the PC, or mobile phone, so that we can choose a different page.

3, User-agent: On the surface is the same concept as the browser type, the actual is not the same. The User-agent range is wider than the browser type. Because, the visitor not only has the browser class, but also has the application, the search robot, as well as the spam website to crawl the information. For spam sites to crawl information, of course, many are disguised, deal with it, it is not processed in UA recognition, but in the IP route processing things.

The UA route in MVC mode is primarily to allow the client to request that the corresponding correct page be displayed eventually.

But PHP does not have a good function, or extensible, maintainable third-party open source, can really quickly do UA recognition.

Get_browser function, although the C language level, but its related INI file is to be downloaded in real time, and, good hundreds of K of a large INI file, in which the search for the correct UA, and then, according to different algorithms to calculate the corresponding results, efficiency, of course, once the download speed is not good, or process too much, the machine memory is tight, the speed straight down immediately. This cannot be said to be a tragedy.

?

The best practice is to put all the UA strings now, completely split out, and we'll find that some strings, certainly robot proprietary, some strings, are definitely mobile proprietary. Thus, to make a CSV, then, now such data, just two fields of less than 1000 records of the file. The file size is also reduced to less than 20KB. The data to be processed is reduced by about 25 times times. Faster than the original speed of 20 times times faster than the original slowest speed faster than 200 times times.

?

Why is it? Think of 1000 records, binary find, need to find out several times? Also, binary finds less than 1000 rows of records in 20KB text, which is certainly much faster than finding more than 20,000 lines of binary lookups in files with more than 400 K.

?

?

?

?

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.