Last active
December 20, 2017 17:06
-
-
Save zeshanshani/d2d904aa271b97641ff0230cdb1d1dfa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 // please don't copy this line. | |
/** | |
* Get SERP Name | |
*/ | |
function jiv_get_serp_name() { | |
if ( isset( $_SERVER['HTTP_REFERER'] ) ) { | |
$serps = array( 'google', 'bing', 'yahoo', 'duckduckgo' ); | |
$referer = $_SERVER['HTTP_REFERER']; | |
$result = jiv_get_domain_from_url( $referer ); | |
$result = explode( ".", $result ); | |
if ( in_array( $result[0], $serps ) ) { | |
return $result[0]; | |
} else { | |
return false; | |
} | |
} | |
return false; | |
} | |
function jiv_get_domain_from_url( $url ) { | |
$pieces = parse_url( $url ); | |
$domain = isset( $pieces['host'] ) ? $pieces['host'] : $pieces['path']; | |
if ( preg_match( '/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs ) ) { | |
return $regs['domain']; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment