Skip to content

Instantly share code, notes, and snippets.

@alaasalama
Created March 8, 2016 12:12
Show Gist options
  • Save alaasalama/1fe178e0bee28cbb867c to your computer and use it in GitHub Desktop.
Save alaasalama/1fe178e0bee28cbb867c to your computer and use it in GitHub Desktop.
Excluding user agents list from loading specific script on your website.
<?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