{"id":153,"date":"2023-02-18T21:06:59","date_gmt":"2023-02-18T13:06:59","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=153"},"modified":"2023-02-18T21:07:22","modified_gmt":"2023-02-18T13:07:22","slug":"php-get-request-path-and-request-parameters","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/php-get-request-path-and-request-parameters\/","title":{"rendered":"PHP\u83b7\u53d6\u8bf7\u6c42\u8def\u5f84\u548c\u8bf7\u6c42\u53c2\u6570"},"content":{"rendered":"<h3>\u83b7\u53d6\u57df\u540d\u6216\u4e3b\u673a\u5730\u5740<\/h3>\n<pre><code class=\"language-php\">echo $_SERVER[&#039;HTTP_HOST&#039;].&quot;&lt;br&gt;&quot;;  \/\/ www.appblog.cn\necho &#039;http:\/\/&#039;.$_SERVER[&#039;HTTP_HOST&#039;].&#039;\/&#039;;  \/\/ http:\/\/www.appblog.cn\/<\/code><\/pre>\n<p><!-- more --><\/p>\n<h3>\u83b7\u53d6\u7f51\u9875\u5730\u5740<\/h3>\n<pre><code class=\"language-php\">echo $_SERVER[&#039;PHP_SELF&#039;].&quot;&lt;br&gt;&quot;;  \/\/ \/Home\/picture<\/code><\/pre>\n<h3>\u83b7\u53d6\u7f51\u5740\u53c2\u6570<\/h3>\n<pre><code class=\"language-php\">echo $_SERVER[&quot;QUERY_STRING&quot;].&quot;&lt;br&gt;&quot;;  \/\/ a=1&amp;b=2<\/code><\/pre>\n<h3>\u83b7\u53d6\u7528\u6237\u4ee3\u7406<\/h3>\n<pre><code class=\"language-php\">echo $_SERVER[&#039;HTTP_REFERER&#039;].&quot;&lt;br&gt;&quot;;  \/\/ http:\/\/www.appblog.cn\/index.php\/Home\/index<\/code><\/pre>\n<h3>\u83b7\u53d6\u5b8c\u6574\u7684url<\/h3>\n<pre><code class=\"language-php\">echo &#039;http:\/\/&#039;.$_SERVER[&#039;HTTP_HOST&#039;].$_SERVER[&#039;REQUEST_URI&#039;].&quot;&lt;br&gt;&quot;;  \/\/ http:\/\/www.appblog.cn\/index.php\/Home\/picture?a=1&amp;b=2\n\necho &#039;http:\/\/&#039;.$_SERVER[&#039;HTTP_HOST&#039;].$_SERVER[&#039;PHP_SELF&#039;].&#039;?&#039;.$_SERVER[&#039;QUERY_STRING&#039;].&quot;&lt;br&gt;&quot;;  \/\/ http:\/\/www.appblog.cn\/Home\/picture?a=1&amp;b=2<\/code><\/pre>\n<h3>\u5305\u542b\u7aef\u53e3\u53f7\u7684\u5b8c\u6574url<\/h3>\n<pre><code class=\"language-php\">echo &#039;http:\/\/&#039;.$_SERVER[&#039;SERVER_NAME&#039;].&#039;:&#039;.$_SERVER[&quot;SERVER_PORT&quot;].$_SERVER[&quot;REQUEST_URI&quot;].&quot;&lt;br&gt;&quot;;  \/\/ http:\/\/www.appblog.cn:80\/index.php\/Home\/picture?a=1&amp;b=2<\/code><\/pre>\n<h3>\u53ea\u53d6\u8def\u5f84<\/h3>\n<pre><code class=\"language-php\">echo &#039;http:\/\/&#039;.$_SERVER[&#039;SERVER_NAME&#039;].$_SERVER[&quot;REQUEST_URI&quot;].&quot;&lt;br&gt;&quot;;  \/\/ http:\/\/www.appblog.cn\/index.php\/Home\/picture?a=1&amp;b=2<\/code><\/pre>\n<h3>HTTP_HOST\u4e0eSERVER_NAME\u7684\u533a\u522b<\/h3>\n<p>\uff081\uff09\u901a\u5e38\u60c5\u51b5<\/p>\n<p><code>$_SERVER[&quot;HTTP_HOST&quot;]<\/code> \u5728HTTP\/1.1\u534f\u8bae\u89c4\u8303\u4e0b\uff0c\u4f1a\u6839\u636e\u5ba2\u6237\u7aef\u7684HTTP\u8bf7\u6c42\u8f93\u51fa\u4fe1\u606f<br \/>\n<code>$_SERVER[&quot;SERVER_NAME&quot;]<\/code> \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u76f4\u63a5\u8f93\u51faApache\u7684\u914d\u7f6e\u6587\u4ef6httpd.conf\u4e2d\u7684ServerName\u503c\uff08\u6216Nginx\u914d\u7f6e\u6587\u4ef6\uff09<\/p>\n<p>\uff082\uff09\u5f53\u670d\u52a1\u5668\u4e3a\u975e80\u7aef\u53e3\u65f6<\/p>\n<p><code>$_SERVER[&quot;HTTP_HOST&quot;]<\/code> \u4f1a\u8f93\u51fa\u7aef\u53e3\u53f7\uff0c\u4f8b\u5982\uff1aappblog.cn:8080<br \/>\n<code>$_SERVER[&quot;SERVER_NAME&quot;]<\/code> \u4f1a\u76f4\u63a5\u8f93\u51faServerName\u503c<\/p>\n<p>\u56e0\u6b64\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\uff1a<code>HTTP_HOST = SERVER_NAME : SERVER_PORT<\/code><\/p>\n<p>\uff083\uff09\u5f53\u914d\u7f6e\u6587\u4ef6httpd.conf\u4e2d\u7684ServerName\u4e0eHTTP\/1.0\u8bf7\u6c42\u7684\u57df\u540d\u4e0d\u4e00\u81f4\u65f6<\/p>\n<p>httpd.conf\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre><code>&lt;virtualhost *&gt;\nServerName appblog.cn\nServerAlias www.appblog.cn\n&lt;\/virtualhost&gt;<\/code><\/pre>\n<p>\u5ba2\u6237\u7aef\u8bbf\u95ee\u57df\u540d<code>www.appblog.cn<\/code><br \/>\n<code>$_SERVER[&quot;HTTP_HOST&quot;]<\/code> \u8f93\u51fa<code>www.appblog.cn<\/code><br \/>\n<code>$_SERVER[&quot;SERVER_NAME&quot;]<\/code> \u8f93\u51fa<code>appblog.cn<\/code><\/p>\n<p>\u6240\u4ee5\uff0c\u5728\u5b9e\u9645\u7a0b\u5e8f\u4e2d\uff0c\u5e94\u5c3d\u91cf\u4f7f\u7528<code>$_SERVER[&quot;HTTP_HOST&quot;]<\/code>\uff0c\u6bd4\u8f83\u4fdd\u9669\u548c\u53ef\u9760\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u83b7\u53d6\u57df\u540d\u6216\u4e3b\u673a\u5730\u5740 echo $_SERVER[&#039;HTTP_HOST&#039;].&quot;&#038;l [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-php-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}