php當前url完整
A. 請問下 php 怎麼獲取 ajax 請求 來源頁面的 完整 url 地址啊
$_SERVER['HTTP_REFERER'] //這個參數可以完全獲取,頁面來源
不過,需要注意,錨鏈接是不能獲取的,
比如:xx.php?name=123#1234
獲取的地址是 xx.php?name=123
因為錨鏈接是前台的東西,是不會發送到後台去的
B. thinkphp 怎麼獲取當前的url完整
<?php
echo$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
若需要顯示協議
<?php
echo$_SERVER["REQUEST_SCHEME"].'://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
C. php如何獲取當前的url
<?php
$url=($_SERVER['HTTP_HTTPS']?'https':'http').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo$url;
?>
D. PHP $_GET['url'];怎麼傳入完整的url
#後面的內容PHP無法獲取,只有js可以獲取,JS代碼示例:
<script type="text/javascript">
document.write(location.href);
</script>
E. php或者js如何取得完整url包括url中含有#的部分,比如:index.php#ac=5
用js的window.location.href,下面是代碼:
function test() {
alert(window.location.href);
}
<a href="#" onclick="test()">test</a>
F. thinkphp 怎麼獲取當前的url完整
<?php
/**
*獲取當前頁面完整URL地址
*/
functionget_url(){
$sys_protocal=isset($_SERVER['SERVER_PORT'])&&$_SERVER['SERVER_PORT']=='443'?'https://':'http://';
$php_self=$_SERVER['PHP_SELF']?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME'];
$path_info=isset($_SERVER['PATH_INFO'])?$_SERVER['PATH_INFO']:'';
$relate_url=isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:$php_self.(isset($_SERVER['QUERY_STRING'])?'?'.$_SERVER['QUERY_STRING']:$path_info);
return$sys_protocal.(isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'').$relate_url;
}
echoget_url();
?>
G. php獲取url參數
1、在當前網頁echo出變數$_SERVER['HTTP_HOST']即可獲取域名或主機地址。
H. 怎麼通過PHP代碼獲取帶#的完整的URL
使用正則表達式獲取
匹配網址URL的正則表達式:^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$
I. 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;}?>
(9)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']."";
J. 怎麼用php獲取當前url 然後存入文檔
//獲取域名或主機地址
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);
寫入文件
$file = "paypal_back.log";
file_put_contents($file, $url, FILE_APPEND);