{"id":3884,"date":"2013-02-10T12:29:14","date_gmt":"2013-02-10T06:59:14","guid":{"rendered":"http:\/\/windowsvj.com\/wpblog\/?p=3884"},"modified":"2013-02-10T13:38:39","modified_gmt":"2013-02-10T08:08:39","slug":"get-current-url-using-php","status":"publish","type":"post","link":"http:\/\/windowsvj.com\/wpblog\/2013\/02\/get-current-url-using-php\/","title":{"rendered":"Get Current URL using PHP"},"content":{"rendered":"<p>The other day I was writing a script where I was required to consume the current webpage url for in the services I was writing. PHP Server variable is quiet handy for such scenarios as it provide all the parameters passed through the server. Though direct information about the current URL is not provided, it can be formed using the following script:<\/p>\n<p>Add the following code to a page:<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\nfunction getCurrentWebpageURL() {\r\n $pageURL = 'http';\r\n if ($_SERVER[\"HTTPS\"] == \"on\") {$pageURL .= \"s\";}\r\n $pageURL .= \":\/\/\";\r\n if ($_SERVER[\"SERVER_PORT\"] != \"80\") {\r\n  $pageURL .= $_SERVER[\"SERVER_NAME\"].\":\".$_SERVER[\"SERVER_PORT\"].$_SERVER[\"REQUEST_URI\"];\r\n } else {\r\n  $pageURL .= $_SERVER[\"SERVER_NAME\"].$_SERVER[\"REQUEST_URI\"];\r\n }\r\n return $pageURL;\r\n}\r\n?&gt;<\/pre>\n<p>You can now get the current page URL using echo\/var_dump or can consume the same directly by assigning to a variable:<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n  echo getCurrentWebpageURL();\r\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>More details about PHP server variables can be find at <a title=\"http:\/\/php.net\/manual\/en\/reserved.variables.server.php\" href=\"http:\/\/php.net\/manual\/en\/reserved.variables.server.php\">http:\/\/php.net\/manual\/en\/reserved.variables.server.php<\/a><\/p>\n<p>To check out the current values of Server variables, var_dump ($SERVER) can be a handy trick as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I was writing a script where I was required to consume the current webpage url for in the services I was writing. PHP Server variable is quiet handy for such scenarios as it provide all the parameters passed through the server. Though direct information about the current [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[258],"tags":[],"class_list":["post-3884","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/posts\/3884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/comments?post=3884"}],"version-history":[{"count":6,"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/posts\/3884\/revisions"}],"predecessor-version":[{"id":3890,"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/posts\/3884\/revisions\/3890"}],"wp:attachment":[{"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/media?parent=3884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/categories?post=3884"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/windowsvj.com\/wpblog\/wp-json\/wp\/v2\/tags?post=3884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}