Last active
May 20, 2019 19:40
-
-
Save edwinvelez/622327776aaf3f2df1c8006f6fd716e8 to your computer and use it in GitHub Desktop.
Compare Two Domain Name Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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