ASP php获取文件URL地址等方法
$_SERVER["HTTP_REFERER"] rss中可用
echo next(explode("=", $_SERVER["QUERY_STRING"]));
echo $_GET[$id];一样的哦
http://www.biuuu.com/index.php?p=222&q=biuuu
结果:
$_SERVER["QUERY_STRING"] = “p=222&q=biuuu”
$_SERVER["REQUEST_URI"] = “/index.php?p=222&q=biuuu”
$_SERVER["SCRIPT_NAME"] = “/index.php”
$_SERVER["PHP_SELF"] = “/index.php”
$_SERVER["QUERY_STRING"]获取查询语句,实例中可知,获取的是?后面的值
$_SERVER["REQUEST_URI"] 获取http://www.biuuu.com后面的值,包括/
$_SERVER["SCRIPT_NAME"] 获取当前脚本的路径,如:index.php
$_SERVER["PHP_SELF"] 当前正在执行脚本的文件名
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
$filename= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
echo $filename;
// 只取 ? 前面的内容
if (strpos($this_page, "?") !== false)
$this_page = reset(explode("?", $this_page));
如果字符串中只有域名:
1
2
3
|
$str = 'aaa.baidu.com' ; preg_match( "/[\w\-]+\.\w+$/" , $str , $arr ); echo $arr [0]; |
用到
如果是完整的URL:
1
2
3
|
$str = 'fdsa.fdsa.baidu.com/fdsa/rewl.html' ; preg_match( "/[\w\-]+\.\w+(?=\/)/" , $str , $arr ); echo $arr [0]; |
- 追问
-
请问如何提取降一级的域名呢如xxx.xxx.com就提取xxx.com而xxx.xxx.xxx.com就匹配xxx.xxx.com
- 回答
-
123456789101112
$str
=
'http://we.aa.baidu.com/dfsa.html'
;
$str2
=
'http://baike.baidu.com/'
;
//正则
$reg
=
"#(?<=\\.)([\\w\-]+\\.)+?\\w+(?=/)#ix"
;
//匹配第一组
preg_match(
$reg
,
$str
,
$arr
);
echo
$arr
[0];
echo
''
;
//匹配第二组
preg_match(
$reg
,
$str2
,
$arr
);
echo
$arr
[0];
嗯,使用正则的断言,很一句代码就实现了。
=================================================================================
=======================================================================================
ASP获取文件URL地址方法
ASP如何获取文件地址呢?直接看例子:
如果要想获取这样的地址:http://192.168.0.5/super/super_article.asp?id=4
那么我们就只要获取:
192.168.0.5---><%=Request.ServerVariables("HTTP_HOST")%>
/super/super_article.asp-----><%=Request.ServerVariables("URL")%>
id=4----><%=Request.ServerVariables("QUERY_STRING")%>
那么我们把上面的地址合起来就可以完成任务了:
http://192.168.0.5/super/super_article.asp?id=4----->;http://<;%=Request.ServerVariables("HTTP_HOST")&request.ServerVariables("URL")&"?"&Request.ServerVariables("QUERY_STRING") %>
使用获取url中的文件名和传过来的值:
本文件ip路径:<%="http://" & request.servervariables("server_name")&request.servervariables("script_name") %> 就可以了..
下面是具体其它一些获取服务器信息的一些方法
几个常用Request.ServerVariables的中文
本文件ip路径:<%="http://" & request.servervariables("server_name")&request.servervariables("script_name") %>
本机ip:<%=request.servervariables("remote_addr")%>
服务器名:<%=Request.ServerVariables("SERVER_NAME")%>
服务器IP:<%=Request.ServerVariables("LOCAL_ADDR")%>
服务器端口:<%=Request.ServerVariables("SERVER_PORT")%>
服务器时间:<%=now%>
IIS版本:<%=Request.ServerVariables("SERVER_SOFTWARE")%>
脚本超时时间:<%=Server.ScriptTimeout%>
本文件路径:<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%>
服务器CPU数量:<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%>
服务器解译引擎:<%=ScriptEngine & "/"& ScriptEngineMajorVersion&"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %>
服务器操作系统:<%=Request.ServerVariables("OS")%>
支持的文件类型:<%=Request.ServerVariables("HTTP_Accept")%>
访问的文件路径:<%=Request.ServerVariables("HTTP_url")%>
用户代理的信息:<%=Request.ServerVariables("HTTP_USER_AGENT")%>
获取url中的文件名和传过来的值:request.ServerVariables("script_name")+"?"+request.ServerVariableS("QUERY_STRING")
ASP如何获取文件所在目录
在ASP中,我们都知道文件的路径怎么获取,但是文件所在目录却不知道怎么办?
我们获取文件的路径是:<%=Request.ServerVariables("PATH_TRANSLATED")%>
既然我们都获取了文件的路径了,那么我们就可以使用函数来处理一下刚才获取的路径,
下面就是我们的处理:
<%=Left(Request.ServerVariables("PATH_TRANSLATED"),instrRev(Request.ServerVariables("PATH_TRANSLATED"),"\"))%>
那么这个输出是什么呢?它就是你要的文件所在的目录路径。
$_SERVER[PHP_SELF] - $_SERVER[SCRIPT_NAME] - $_SERVER['REQUEST_URI']
$_SERVER[’PHP_SELF’]
- http://www.yoursite.com/example/ — – — /example/index.php
- http://www.yoursite.com/example/index.php — – — /example/index.php
- http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
- http://www.yoursite.com/example/index.php/dir/test — – — /dir/test
当我们使用$_SERVER['PHP_SELF']的时候,无论访问的URL地址是否有index.php,它都会自动的返回 index.php.但是如果在文件名后面再加斜线的话,就会把后面所有的内容都返回在$_SERVER['PHP_SELF']。
$_SERVER['REQUEST_URI']
- http://www.yoursite.com/example/ — – — /
- http://www.yoursite.com/example/index.php — – — /example/index.php
- http://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=test
- http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test
$_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,如果URL只写到”/”,就返回 “/”
$_SERVER['SCRIPT_NAME']
- http://www.yoursite.com/example/ — – — /example/index.php
- http://www.yoursite.com/example/index.php — – — /example/index.php
- http://www.yoursite.com/example/index.php — – — /example/index.php
- http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php
在所有的返回中都是当前的文件名/example/index.php
ASP php获取文件URL地址等方法的更多相关文章
- php获取当前url地址的方法小结
js 获取: top.location.href //顶级窗口的地址 this.location.href //当前窗口的地址 php获取当前url地址: #测试网址: http://localhos ...
- asp.net 获取当前url地址
设当前页完整地址是:http://www.jb51.net/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www.jb5 ...
- 获取网页URL地址及参数等的两种方法(js和C#)
转:获取网页URL地址及参数等的两种方法(js和C#) 一 js 先看一个示例 用javascript获取url网址信息 <script type="text/javascript&q ...
- PHP 获取完整URL地址
/** * 获取当前完整URL * @return string */ function get_url() { $sys_protocal = isset($_SERVER['SERVER_PORT ...
- Javascript 获取链接(url)参数的方法
有时我们需要在客户端获取链接参数,一个常见的方法是将链接当做字符串,按照链接的格式分解,然后获取对应的参数值.本文给出的就是这个流程的具体实现方法. 当然,我们也可以用正则直接匹配,文章中也给出了一个 ...
- Flask框架获取用户IP地址的方法
本文实例讲述了python使用Flask框架获取用户IP地址的方法.分享给大家供大家参考.具体如下: 下面的代码包含了html页面和python代码,非常详细,如果你正使用Flask,也可以学习一下最 ...
- python获取文件扩展名的方法(转)
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...
- python获取文件扩展名的方法
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...
- 织梦文章页调用当前栏目名称和url地址的方法
其实织梦本身有这2个调用标签,可能大家没怎么注意,下面的代码就是织梦文章页调用当前栏目名称和url地址的方法: {dede:field name='typeurl' function=”GetType ...
随机推荐
- 网络请求 get post
1.新建一个网络请求工具类,负责整个项目中所有的Http网络请求 提示:同步请求会卡住线程,发送网络请求应该使用异步请求(这意味着类方法不能有返回值) 2.工具类的实现 YYHttpTool.h文件 ...
- Shell脚本,自动化发布tomcat项目【转】
Shell脚本,自动化发布tomcat项目脚本. 1. vko2c_auto_build_by_scp.sh 文件内容: #---------------------start------------ ...
- 缩放系列(二):所有子控件也随着缩放、手势缩放、多点触控layout
下面是一个功能强大的改造的例子: 可以实现以下需求: 1.两个手指进行缩放布局 2.所有子控件也随着缩放, 3.子控件该有的功能不能丢失(像button有可被点击的功能,缩放后不能丢失该功能) 运行效 ...
- HttpWebResponse远程服务器返回错误: (500) 内部服务器错误
现象 我们编码实现请求一个页面时,请求的代码类似如下代码: HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strUrl);req.Use ...
- Java学习笔记之static
1.static可以用于修饰成员变量.方法以及块,并不会改变类中成员的权限修饰,如:private修饰的成员变量,类外只能类名或非私有方法调用,而不能使用对象名调用. 2.static方法和成员变量, ...
- undefined与null
undefined 声明的变量尚未初始化 null 对象尚未存在 eg: var a; console.log(typeof a); 输出undefined var b= document.getEl ...
- 软件设计模式详解:OCP原则
看到两篇关于OCP的文章, 纳之. 原文: http://www.cnblogs.com/muzongyan/archive/2010/08/05/1793454.html http://blog. ...
- Batch Sort
Batch Sort time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- C++调用C#之C++DLL调用C# COM控件
1. 新建项目 这里我们使用ATL,来接受C# COM控件向外发送的事件. 2. 初始化ATL #include "stdafx.h" CComModule _module; BO ...
- Swift: Alamofire -> http请求 & ObjectMapper -> 解析JSON
1 2 3 4 5 6 7 8 9 10 11 NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.js ...