Path_Url.php
来源:原创
时间:2016-07-23
作者:脚本小站
分类:代码笔记
<?php //============================================================ //------------------------------------------------------------ $_SERVER["HTTP_REFERER"] //用户访问的上一个页面地址 /* 可用做防止盗链,当此地址的域名不是允许的域名时, 可做屏蔽图片操作 */ //------------------------------------------------------------ //------------------------------------------------------------ //超全局数组 $_ENV; //环境变量 $_GLOBALS[]; //包含GET POST SERVER 等 $_SERVER['SERVER_NAME']; // localhost $_SERVER['SCRIPT_NAME']; // /demo.php $_SERVER['QUERY_STRING']; // a=d&c=d $_SERVER['PATH_INFO']; // index.php/index/index __FILE__ //当前脚本的路径 strpos($string,'a') //查找字符是否存在 parse_url //$url = 'http://username:password@hostname/path?arg=value#anchor'; /* Array( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor ) */ parse_str // id=12&name=Stephen -> array('id'=>'12','name'=>'Stephen') http_build_query // array('id'=>'12','name'=>'Stephen') -> id=12&name=Stephen //=========================================================== //-----------------------路径处理--------------------------- /* path:C:/name/hello/hello.php url:/name/hello/hello.php?action=del&name=hello */ //------------------------------------------------------- //-----------------获取完整的地址路径------------------- $_SERVER["REQUEST_URI"] /*例: 当前地址栏中的值 http://localhost/demo.php?id=2&name=Stephen echo $_SERVER["REQUEST_URI"]; 则输出为:/dir/demo.php?id=2&name=Stephen */ //-------------------------------------------------------- //------------------取得历史请求信息--------------------- $_SERVER['QUERY_STRING'] /* echo $_SERVER['QUERY_STRING']; 输出:id=2&name=Stephen */ //-------------------------------------------------------- //--------------------取得当前post或get请求信息---------- $_REQUEST /* Array ( [action] => add [id] => 12 )*/ //-------------------------------------------------------- //-----------------获取脚本所在路径---------------------- $_SERVER["SCRIPT_NAME"]; /* echo $_SERVER["SCRIPT_NAME"]; 输出:/dir/demo.php */ //============================================================ //----------------------parse_url()--------------------------- /* 解析url的各个部分 */ $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); /*输出: Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor ) */ //---------------------------------------------------- //------------------parse_str()----------------------- /* url后面的参数 -> 键=>值 or 变量=值 */ parse_str("id=23&name=John%20Adams"); echo $id."<br />"; echo $name; parse_str("uid=ioio&hj=hjk",$parse); print_r($parse); /* Array ( [uid] => ioio [hj] => hjk )*/ //----------------------------------------------------- //-------pathinfo()返回文件路径的信息----------------* print_r(pathinfo("/testweb/test.txt")); /*输出:Array ( [dirname] => /testweb [basename] => test.txt [extension] => txt )*/ pathinfo('/testweb/test.txt',PATHINFO_EXTENSION); PATHINFO_DIRNAME //只返回 dirname PATHINFO_BASENAME //只返回 basename PATHINFO_EXTENSION //只返回 extension dirname() //返回路径中的目录部分 basename() //返回路径中的文件名部分 //=========================================================== //------------------------__FILE__--------------------------- print_r(pathinfo(__FILE__)); /*Array( [dirname] => C:\lamp\apache2\htdocs [basename] => test.php [extension] => php [filename] => test )*/ echo pathinfo("/testweb/test.txt",PATHINFO_BASENAME); //输出:test.txt //不同输出参数 PATHINFO_DIRNAME // 只返回 dirname PATHINFO_BASENAME // 只返回 basename PATHINFO_EXTENSION // 只返回 extension //============================================================ //------------------realpath()返回绝对路径名----------------- // 删除所有符号连接(比如 '/./', '/../' 以及多余的 '/'),返回绝对路径名 echo realpath("test.txt"); // C:\Inetpub\testweb\test.txt //============================================================ //------------------------------------------------------------ //------------------------$_SERVER---------------------------- $_SERVER;