{"id":343,"date":"2011-02-23T17:29:01","date_gmt":"2011-02-23T23:29:01","guid":{"rendered":"http:\/\/www.cavanaugh.pro\/sean\/?p=343"},"modified":"2011-03-10T17:35:12","modified_gmt":"2011-03-10T23:35:12","slug":"how-to-grab-your-url-with-php","status":"publish","type":"post","link":"https:\/\/www.cavanaugh.pro\/sean\/how-to-grab-your-url-with-php\/","title":{"rendered":"How to Grab your URL with PHP"},"content":{"rendered":"<p>Sometimes you want to grab your url from the web browser to do some thinking (maybe I want to display flowers on a random page, or want to display a lock if https is enabled).  Here is some code that I have seen used over and over, and I have taken parts of it and used it for many a web project.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\nfunction curPageURL() {\r\n $pageURL = 'http';\r\n if ($_SERVER&#x5B;&quot;HTTPS&quot;] == &quot;on&quot;) {$pageURL .= &quot;s&quot;;}\r\n $pageURL .= &quot;:\/\/&quot;;\r\n if ($_SERVER&#x5B;&quot;SERVER_PORT&quot;] != &quot;80&quot;) {\r\n  $pageURL .= $_SERVER&#x5B;&quot;SERVER_NAME&quot;].&quot;:&quot;.$_SERVER&#x5B;&quot;SERVER_PORT&quot;].$_SERVER&#x5B;&quot;REQUEST_URI&quot;];\r\n } else {\r\n  $pageURL .= $_SERVER&#x5B;&quot;SERVER_NAME&quot;].$_SERVER&#x5B;&quot;REQUEST_URI&quot;];\r\n }\r\n return $pageURL;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>now you can use the function<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n  echo curPageURL();\r\n?&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you want to grab your url from the web browser to do some thinking (maybe I want to display flowers on a random page, or want to display a lock if https is enabled). Here is some code that I have seen used over and over, and I have taken parts of it and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.cavanaugh.pro\/sean\/how-to-grab-your-url-with-php\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Grab your URL with PHP&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-343","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts\/343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/comments?post=343"}],"version-history":[{"count":4,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts\/343\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/posts\/343\/revisions\/348"}],"wp:attachment":[{"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/media?parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/categories?post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cavanaugh.pro\/sean\/wp-json\/wp\/v2\/tags?post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}