php 获取URL地址

来源:http://www.cnblogs.com/A-Song/archive/2011/12/14/2288215.html

#测试网址:     http://localhost/blog/testurl.php?id=5

//获取域名或主机地址 
echo $_SERVER['HTTP_HOST']."<br>"; #localhost

//获取网页地址 
echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php

//获取网址参数 
echo $_SERVER["QUERY_STRING"]."<br>"; #id=5

//获取用户代理 
echo $_SERVER['HTTP_REFERER']."<br>"; 

//获取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5

//包含端口号的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
#http://localhost:80/blog/testurl.php?id=5

//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; 
echo dirname($url);
#http://localhost/blog

 

php判断设备是否手机

function is_mobile() {
  $user_agent = $_SERVER ['HTTP_USER_AGENT'];
  $mobile_browser = Array (
      "mqqbrowser", // 手机QQ浏览器
      "opera mobi", // 手机opera
      "juc",
      "iuc", // uc浏览器
      "fennec",
      "ios",
      "applewebKit/420",
      "applewebkit/525",
      "applewebkit/532",
      "ipad",
      "iphone",
      "ipaq",
      "ipod",
      "iemobile",
      "windows ce", // windows phone
      "240×320",
      "480×640",
      "acer",
      "android",
      "anywhereyougo.com",
      "asus",
      "audio",
      "blackberry",
      "blazer",
      "coolpad",
      "dopod",
      "etouch",
      "hitachi",
      "htc",
      "huawei",
      "jbrowser",
      "lenovo",
      "lg",
      "lg-",
      "lge-",
      "lge",
      "mobi",
      "moto",
      "nokia",
      "phone",
      "samsung",
      "sony",
      "symbian",
      "tablet",
      "tianyu",
      "wap",
      "xda",
      "xde",
      "zte"
  );
  $is_mobile = false;
  foreach ( $mobile_browser as $device ) {
    if (stristr ( $user_agent, $device )) {
      $is_mobile = true;
      break;
    }
  }
  return $is_mobile;
}

 

修改 Apache配置允许局域网内所有访问

/*
*/
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

//修改后
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all 
</Directory>
/*
*/
#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1

//修改后
#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from none
    Allow from all