Home Backend Development PHP Tutorial PHP Get IE Browser Version Function_PHP Tutorial

PHP Get IE Browser Version Function_PHP Tutorial

Jul 13, 2016 pm 05:16 PM
php s use information function Can exist us Browser Version Obtain want

In php, if we want to obtain browser information, we can directly use $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]); and then make a further judgment to determine the user's browser version or model. I hope the following example will be helpful to everyone Helps.

The author below will introduce to you a php function that determines whether the user's browser is IE6. If so, it will return "true", otherwise it will return "false".

The code is as follows Copy code
 代码如下 复制代码

function isIE6() {
       $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
       //从HTTP_USER_AGENT字段中获取用户浏览器信息
       if (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
               return true;
       }
       return false;
}

function isIE6() {
        $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
//Get user browser information from HTTP_USER_AGENT field
If (ereg("msie 6", $userAgent) || ereg("msie 5", $userAgent)) {
                    return true;
}                                               return false;
}

Complete example

http://www.bkjia.com/PHPjc/628712.html
 代码如下 复制代码

function userBrowser(){ 
       $user_OSagent = $_SERVER['HTTP_USER_AGENT'];  
    
        if(strpos($user_OSagent,"Maxthon") && strpos($user_OSagent,"MSIE")) {  
           $visitor_browser ="Maxthon(Microsoft IE)";  
       }elseif(strpos($user_OSagent,"Maxthon 2.0")) {  
            $visitor_browser ="Maxthon 2.0";  
       }elseif(strpos($user_OSagent,"Maxthon")) {  
           $visitor_browser ="Maxthon";  
        }elseif(strpos($user_OSagent,"MSIE 9.0")) {  
           $visitor_browser ="MSIE 9.0";  
       }elseif(strpos($user_OSagent,"MSIE 8.0")) {  
            $visitor_browser ="MSIE 8.0";  
       }elseif(strpos($user_OSagent,"MSIE 7.0")) {  
            $visitor_browser ="MSIE 7.0";  
        }elseif(strpos($user_OSagent,"MSIE 6.0")) {  
           $visitor_browser ="MSIE 6.0";  
        } elseif(strpos($user_OSagent,"MSIE 5.5")) {  
            $visitor_browser ="MSIE 5.5";  
        } elseif(strpos($user_OSagent,"MSIE 5.0")) {  
            $visitor_browser ="MSIE 5.0";  
        } elseif(strpos($user_OSagent,"MSIE 4.01")) {  
          $visitor_browser ="MSIE 4.01";  
        }elseif(strpos($user_OSagent,"MSIE")) {  
           $visitor_browser ="MSIE 较高版本";  
      }elseif(strpos($user_OSagent,"NetCaptor")) {  
            $visitor_browser ="NetCaptor";  
        } elseif(strpos($user_OSagent,"Netscape")) {  
           $visitor_browser ="Netscape";  
      }elseif(strpos($user_OSagent,"Chrome")) {  
           $visitor_browser ="Chrome";  
        } elseif(strpos($user_OSagent,"Lynx")) {  
          $visitor_browser ="Lynx";  
       } elseif(strpos($user_OSagent,"Opera")) {  
           $visitor_browser ="Opera";  
        } elseif(strpos($user_OSagent,"Konqueror")) {  
            $visitor_browser ="Konqueror";  
        } elseif(strpos($user_OSagent,"Mozilla/5.0")) {  
            $visitor_browser ="Mozilla";  
           } elseif(strpos($user_OSagent,"Firefox")) {                                                                             $visitor_browser ="Firefox";                                                   }elseif(strpos($user_OSagent,"U")) {                                                                    $visitor_browser ="Firefox";                                                                                 $visitor_browser = "Other";                                                                                                  return $visitor_browser;                                                    } 







www.bkjia.comtrue

http: //www.bkjia.com/PHPjc/628712.html

In php, if we want to obtain browser information, we can directly use $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"] ); Then you can judge the user's browser version or model,...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP: An Introduction to the Server-Side Scripting Language PHP: An Introduction to the Server-Side Scripting Language Apr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term Impact PHP and the Web: Exploring its Long-Term Impact Apr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

See all articles