{"id":256,"date":"2009-03-04T07:14:47","date_gmt":"2009-03-04T07:14:47","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=256"},"modified":"2010-07-17T01:35:46","modified_gmt":"2010-07-17T01:35:46","slug":"how-to-get-the-page-url-with-php-code","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2009\/03\/how-to-get-the-page-url-with-php-code\/","title":{"rendered":"How to Get the Page URL with php code?"},"content":{"rendered":"<p>Every php coder ask questions to get CURRENT PAGE URL with PHP,  it is not as straightforward in raw php coding as one may think to get the current url to use it inside your application. Here is a code which you can use to get url easily.<\/p>\n<pre name=\"code\" class=\"php\">\r\n\r\nfunction CPageURL() {\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\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Every php coder ask questions to get CURRENT PAGE URL with PHP, it is not as straightforward in raw php coding as one may think to get the current url to use it inside your application. Here is a code which you can use to get url easily. function CPageURL() { $pageURL = &#8216;http&#8217;; if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-256","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":17,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":859,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/256\/revisions\/859"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}