Skip to content

Instantly share code, notes, and snippets.

@edwinvelez
Last active May 20, 2019 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinvelez/622327776aaf3f2df1c8006f6fd716e8 to your computer and use it in GitHub Desktop.
Save edwinvelez/622327776aaf3f2df1c8006f6fd716e8 to your computer and use it in GitHub Desktop.
Compare Two Domain Name Values
<?php
/**
* Compare Two Domain Name Values
*
* @author Edwin Velez (https://edwinvelez.net)
* @link https://edwinvelez.net/compare-two-domain-name-values/
*/
// The domain name or host you want to compare. Can also be a host i.e. http://localhost
$live_site_url = 'https://edwinvelez.net';
$head_pattern = '/(https?:\/\/(w{3}\.)?)?(^w{3}\.)?';
$tail_pattern = '(\:[0-9]+).*|\b\/.*|\b\?.*';
$head_vs_tail_boolean = '|';
$regex_flags = '/m';
$regex_pattern = $head_pattern . $head_vs_tail_boolean . $tail_pattern . $regex_flags;
// Strip everything before and after actual domain name and hostname.
$live_site_url = preg_replace( $regex_pattern, '', strtolower( $live_site_url ) );
$site_url = preg_replace( $regex_pattern, '', strtolower( get_site_url() ) );
$is_live_site = strcmp( $site_url, $live_site_url );
// Is the web browser pointing to the live site?
if ( $is_live_site === 0 ) {
// Insert code here to run if this is your live site.
} else {
// Insert code here to run if this is not your live site.
}
http://edwinvelez.net
http://edwinvelez.net/
https://edwinvelez.net
https://edwinvelez.net/
edwinvelez.net
www.edwinvelez.net
edwinvelez.net/testing/another?sdf=123
www.edwinvelez.net/testing/another?sdf=123
edwinvelez.net:3000/testing/another?sdf=123
www.edwinvelez.net:3000/testing/another?sdf=123
www.edwinvelez.net:3000?sdf=123
http://edwin-velez.net
https://edwin-velez.net
http://edwinvelez.net/testing/another?sdf=123
https://edwinvelez.net/testing/another?sdf=123
http://edwinvelez.net:3000/testing/another?sdf=123
https://edwinvelez.net:3000/testing/another?sdf=123
http://edwinvelez.net:3000?sdf=123
https://edwinvelez.net:3000?sdf=123
http://edwinvelez.net?sdf=123
https://edwinvelez.net?sdf=123
http://localhost
https://localhost
http://www.localhost
https://www.localhost
http://localhost:3000
https://localhost:3000
https://localhost:3000/
http://www.localhost:3000/testing/another?sdf=123
https://www.localhost:3000/testing/another?sdf=123
http://www.localhost:3000?sdf=123
https://www.localhost:3000?sdf=123
http://www.localhost.me.you:3000/testing/another?sdf=123
https://www.localhost.me.you:3000?sdf=123
http://www.localhost.me.you:3000
https://www.localhost.me.you:3000
http://www.edwinvelez.www.net
https://www.edwinvelez.www.net
http://subdomain.subdomain.www.edwinvelez.net/testing/another?sdf=123
https://subdomain.subdomain.www.edwinvelez.net/testing/another?sdf=123
http://subdomain.subdomain.www.edwinvelez.net:9871/testing/another?sdf=123
https://subdomain.subdomain.www.edwinvelez.net:9871/testing/another?sdf=123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment