RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment

Get Current Page URL With PHP

The following function permits you to get the current page (or permalink) URL with PHP. Not unlike regular expression variations, there are numerous methods to return the current URL... so expect this function to evolve over time.

1
<?php 
2
/*
3
 Get Current URL With PHP
4
 http://www.beliefmedia.com/code/php-snippets/current-url-php
5
*/
6
 
7
function beliefmedia_get_url() {
8
 
9
  $url = ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) ? 'https' : 'http';
10
  $url .= '://' . $_SERVER['SERVER_NAME'];
11
  $url .= in_array( $_SERVER['SERVER_PORT'], array( '80', '443' ) ) ? '' : ":" . $_SERVER['SERVER_PORT'];
12
  $url .= $_SERVER['REQUEST_URI'];
13
 
14
 return $url;
15
}
16
 
17
/* Usage */
18
echo beliefmedia_get_url();

If used on this page, the function would return http://www.beliefmedia.com/code/php-snippets/current-url-php.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Connecticut)

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment