Home > php教程 > php手册 > HTTP_REFERER 与 HTTP_USER_AGENT的使用方法

HTTP_REFERER 与 HTTP_USER_AGENT的使用方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-02 09:14:19
Original
1559 people have browsed it

该脚本的输出可能是:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

PHP 有很多种不同类型的变量,在以上例子中我们打印了一个数组的元素,数组是一类非常有用的变量.

$_SERVER 只是 PHP 自动全局化的变量之一,您可以查阅“保留变量”一节来查看这些变量的列表,或者也可以建立如下的文件来得到一个完整的列表.

php 根据HTTP_USER_AGENT 判断用户浏览器类型,代码如下:

function browsers() {
    global $HTTP_USER_AGENT;
    if (isset($HTTP_USER_AGENT)) {
        $sAgent = $HTTP_USER_AGENT;
    } else {
        $sAgent = $_SERVER['HTTP_USER_AGENT'];
    }
    if (strpos($sAgent, 'MSIE') !== false && strpos($sAgent, 'mac') === false && strpos($sAgent, 'Opera') === false) {
        $iVersion = (float)substr($sAgent, strpos($sAgent, 'MSIE') + 5, 3);
        return ($iVersion >= 5.5);
    } else if (strpos($sAgent, 'Gecko/') !== false) {
        $iVersion = (int)substr($sAgent, strpos($sAgent, 'Gecko/') + 6, 8);
        return ($iVersion >= 20030210);
    } else {
        return false;
    }
}
Copy after login

可以得到链接/提交当前页的父页面URL,代码如下:

<?php
if (isset($_SERVER[&#39;HTTP_REFERER&#39;])) {
    print "The page you were on previously was {$_SERVER[&#39;HTTP_REFERER&#39;]}<br />";
} else {
    print "You didn&#39;t click any links to get here<br />";
}
?>
<a href="refer.php">Click me!</a>
Copy after login

               
               

教程网址:

欢迎收藏∩_∩但请保留本文链接。

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template