
正文
phpurl数据函数 php function allow_url
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何通过PHP获取当前页面URL函数
通过PHP获取当前页面URL函数代码如下,调用时只需要使用 curPageURL() 就可以:
/* 获得当前页面URL开始 */
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") { // 如果是SSL加密则加上“s”
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
/* 获得当前页面URL结束 */
相关问答
Q1: php打开URL的几种方法
PHP中打开URL地址的几种方法总结,这里的函数主要用于小偷采集等函数。
1: 用file_get_contents
以get方式获取内容
复制代码 代码如下:
?php
$url='';
$html = file_get_contents($url);
//print_r($http_response_header);
ec($html);
printhr();
printarr($http_response_header);
printhr();
?
示例代码2: 用fopen打开url,
以get方式获取内容
复制代码 代码如下:
?
$fp = fopen($url, 'r');
printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)) {
$result .= fgets($fp, 1024);
}
echo "url body: $result";
printhr();
fclose($fp);
?
示例代码3:用file_get_contents函数,以post方式获取url
复制代码 代码如下:
?php
$data = array ('foo' =
'bar');
$data = http_build_query($data);
$opts = array (
'http'
= array (
'method' = 'POST',
'header'= "Content-type:
application/x-www-form-urlencoded" .
"Content-Length: " . strlen($data) .
"",
'content' = $data
),
);
$context =
stream_context_create($opts);
$html =
file_get_contents('', false, $context);
echo $html;
?
示例代码4:用fsockopen函数打开url,以get方式获取完整的数据,包括header和body
复制代码 代码如下:
?
function get_url
($url,$cookie=false) {
$url = parse_url($url);
$query =
$url[path]."?".$url[query];
ec("Query:".$query);
$fp = fsockopen(
$url[host], $url[port]?$url[port]:80 , $errno, $errstr, 30);
if (!$fp) {
return false;
} else {
$request = "GET $query HTTP/1.1";
$request .= "Host: $url[host]";
$request .= "Connection: Close";
if($cookie) $request.="Cookie: $cookie\n";
$request.="";
fwrite($fp,$request);
while(!@feof($fp)) {
$result .= @fgets($fp,
1024);
}
fclose($fp);
return $result;
}
}
//获取url的html部分,去掉header
function GetUrlHTML($url,$cookie=false) {
$rowdata = get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return $body;
}
return false;
}
?
Q2: php处理url的几个函数
pathinfo
[php] view plaincopy
?php
$test = pathinfo("");
print_r($test);
?
结果如下
Array
(
[dirname] = //url的路径
[basename] = index.php //完整文件名
[extension] = php //文件名后缀
[filename] = index //文件名
)
parse_url
[php] view plaincopy
?php
$test = parse_url(";sex=1#top");
print_r($test);
?
结果如下
Array
(
[scheme] = http //使用什么协议
[host] = localhost //主机名
[path] = /index.php //路径
[query] = name=tanksex=1 // 所传的参数
[fragment] = top //后面根的锚点
)
basename
[php] view plaincopy
?php
$test = basename(";sex=1#top");
echo $test;
?
结果如下
index.php?name=tanksex=1#top
希望能帮到你。
phpurl数据函数的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php function allow_url、phpurl数据函数的信息别忘了在本站进行查找喔。








