{"id":2750,"date":"2023-09-20T20:18:53","date_gmt":"2023-09-20T12:18:53","guid":{"rendered":"https:\/\/www.tra56.com\/?p=2750"},"modified":"2023-09-20T20:18:53","modified_gmt":"2023-09-20T12:18:53","slug":"2750","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/2750.html","title":{"rendered":"php \u83b7\u53d6\u5b8c\u6574url\u5730\u5740"},"content":{"rendered":"

\u4e3b\u8981\u662f\u83b7\u53d6\u5230\u5730\u5740\u680f\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u57df\u540d\uff0c\u7aef\u53e3\u53c2\u6570\u7b49 <\/span><\/p>\n

<?php \r\n\/\/\u83b7\u53d6\u57df\u540d\u6216\u4e3b\u673a\u5730\u5740 \r\necho $_SERVER['HTTP_HOST']."<br>"; \r\n\/\/\u83b7\u53d6\u7f51\u9875\u5730\u5740 \r\necho $_SERVER['PHP_SELF']."<br>"; \r\n\/\/\u83b7\u53d6\u7f51\u5740\u53c2\u6570 \r\necho $_SERVER["QUERY_STRING"]."<br>"; \r\n\/\/\u6765\u6e90\u7f51\u9875\u7684\u8be6\u7ec6\u5730\u5740 \r\necho $_SERVER['HTTP_REFERER']."<br>"; \r\n?><\/pre>\n

php \u83b7\u5f97\u5f53\u524d\u7684\u811a\u672c\u7f51\u5740(\u53ea\u6709\u8def\u5f84)<\/span><\/p>\n

function GetCurUrl() \r\n{ \r\nif(!empty($_SERVER["REQUEST_URI"])) \r\n{ \r\n$scrtName = $_SERVER["REQUEST_URI"]; \r\n$nowurl = $scrtName; \r\n} \r\nelse \r\n{ \r\n$scrtName = $_SERVER["PHP_SELF"]; \r\nif(empty($_SERVER["QUERY_STRING"])) \r\n{ \r\n$nowurl = $scrtName; \r\n} \r\nelse \r\n{ \r\n$nowurl = $scrtName."?".$_SERVER["QUERY_STRING"]; \r\n} \r\n} \r\nreturn $nowurl; \r\n} \r\n\/\/\u5b9e\u4f8b\u8c03\u7528\u65b9\u6cd5 \r\n\/\/echo GEtCurUrl();<\/pre>\n

php \u83b7\u53d6url\u5730\u5740\u4e0d\u5305\u542b\u8def\u5f84\uff08\u57df\u540d\u6216ip\u5730\u5740\uff09<\/span><\/p>\n

function getServerName() \r\n{ \r\n$ServerName = strtolower($_SERVER['SERVER_NAME']?$_SERVER['SERVER_NAME']:$_SERVER['HTTP_HOST']); \r\nif( strpos($ServerName,'http:\/\/') ) \r\n{ \r\nreturn str_replace('http:\/\/','',$ServerName); \r\n} \r\nreturn $ServerName; \r\n} \r\n\/\/\u5b9e\u4f8b\u8c03\u7528\u65b9\u6cd5 \r\necho getServerName();<\/pre>\n

php \u83b7\u53d6url\u5730\u5740\u5305\u542b\u7aef\u53e3\u8def\u5f84<\/span><\/p>\n

echo 'http:\/\/'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];<\/pre>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e3b\u8981\u662f\u83b7\u53d6\u5230\u5730\u5740\u680f\u7684\u4e00\u4e9b\u4fe1\u606f\uff0c\u57df\u540d\uff0c\u7aef\u53e3\u53c2\u6570\u7b49  <?php  \/\/\u83b7\u53d6\u57df\u540d\u6216\u4e3b\u673a\u5730 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,92],"tags":[],"class_list":["post-2750","post","type-post","status-publish","format-standard","hentry","category-php","category-phpcode"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2750"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=2750"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2750\/revisions"}],"predecessor-version":[{"id":2751,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/2750\/revisions\/2751"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=2750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=2750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=2750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}