php獲取頁面url
① php打開URL的幾種方法
PHP中打開URL地址的幾種方法總結,這里的函數主要用於小偷採集等函數。
1:用file_get_contents
以get方式獲取內容
復制代碼代碼如下:
<?php
$url='http://www..com/';
$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"urlbody:$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('http://localhost/e/admin/test.html',false,$context);
echo$html;
?>
示例代碼4:用fsockopen函數打開url,以get方式獲取完整的數據,包括header和body
復制代碼代碼如下:
<?
functionget_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){
returnfalse;
}else{
$request="GET$queryHTTP/1.1";
$request.="Host:$url[host]";
$request.="Connection:Close";
if($cookie)$request.="Cookie:$cookie ";
$request.="";
fwrite($fp,$request);
while(!@feof($fp)){
$result.=@fgets($fp,
1024);
}
fclose($fp);
return$result;
}
}
//獲取url的html部分,去掉header
functionGetUrlHTML($url,$cookie=false){
$rowdata=get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return$body;
}
returnfalse;
}
?>
② php獲取url參數
1、在當前網頁echo出變數$_SERVER['HTTP_HOST']即可獲取域名或主機地址。
③ 如何通過php獲取提交頁面的URL
在PHP的開發中我們經常會通過網址URL向另一個網頁傳遞參數的問題。在這個過程中我們首先需要獲取到當前頁面的URL,然後將URL中各個參數的值保存到變數中。整個過程較為簡單,主要涉及到$_SERVER的用法。
1、$_server['http_host'],作用:獲取網址域名,如(www.5ibobo.com,這是波波的一個博客,暫且做例子吧)。
2、$_SERVER["PHP_SELF"],作用:獲取網頁地址,如(/code/445.html)。
3、$_SERVER["QUERY_STRING"],作用:獲取網址URL參數,待會我們會在實例中用到。
4、$_SERVER["HTTP_REFERER"],作用:獲取用戶的代理。
④ php如何獲取調用頁面的來源地址
使用PHP編寫程序的時候,想要獲取當前頁面的URL,可以了用函數來實現;
參考方法如下:
php
//說明:獲取完整URL
functioncurPageURL()
{
$pageURL='http';
if($_SERVER["HTTPS"]=="on")
{
$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;
}
?>
⑤ php如何獲取當前頁面url路徑
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
{
$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;}?>
(5)php獲取頁面url擴展閱讀:
獲取域名或主機地址 :echo $_SERVER['HTTP_HOST'].""; #localhost
獲取網頁地址:echo $_SERVER['PHP_SELF'].""; #/blog/testurl.php
3.獲取網址參數:echo $_SERVER["QUERY_STRING"].""; #id=5
4.獲取用戶代理:echo $_SERVER['HTTP_REFERER']."";
⑥ php怎樣獲得鏈接來源url
使用PHP編寫程序的時候,想要獲取當前頁面的URL,可以了用函數來實現;參考方法如下:php//說明:獲取完整URLfunctioncurPageURL(){$pageURL='http';if($_...
⑦ php取頁面所有的URL怎麼實現
function get_all_url($code){ preg_match_all(『/"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i』,$code,$arr); return array(『name』=>$arr[2],』url』=>$arr[1]);}
⑧ PHP CodeIgniter框架中怎麼獲取當前頁面的URL
1.
默認情況,你的
url
中會包含 index.php 文件:
如果你的
apache
伺服器啟用了 mod_rewrite ,你可以簡單的通過一個
.htaccess
文件再加上一些簡單的規則就可以移除
index.php
了。下面是這個文件的一個例子,
其中使用了
"否定條件"
來排除某些不需要重定向的項目:
rewriteengine on
rewritecond %{request_filename} !-f
rewritecond %{request_filename} !-d
rewriterule ^(.*)$ index.php/$1 [l]簡單的說就是:在網站根目錄新建一個名字為:「.htaccess」的文件,文件內容拷貝上面4行代碼即可!
2.
如果你使用的iis伺服器的話,需要安裝rewrite模塊,可以去網路一找一下,很多