Created
March 8, 2016 12:12
-
-
Save alaasalama/1fe178e0bee28cbb867c to your computer and use it in GitHub Desktop.
Excluding user agents list from loading specific script on your website.
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 | |
$UA_list = array("GT-I9300","SM-N900T"); //list all user agents you want to block here "using any keyword" | |
$current_UA = $_SERVER['HTTP_USER_AGENT']; //getting the current user agent | |
$matchFound = preg_match_all("/\b(" . implode($UA_list,"|") . ")\b/i",$current_UA,$matches); //check if the current user agent is in the block list | |
if($matchFound){ | |
//do nothing! | |
}else{ //print the script | |
?> | |
<script>(function(d, s, id) { | |
var js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)) return; | |
js = d.createElement(s); js.id = id; | |
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=794034927388702"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk'));</script> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment