Skip to content

Instantly share code, notes, and snippets.

@meowmanijado
Last active July 19, 2017 06:28
Show Gist options
  • Save meowmanijado/a8a4655238dd8fc3badcdb4650afd6dc to your computer and use it in GitHub Desktop.
Save meowmanijado/a8a4655238dd8fc3badcdb4650afd6dc to your computer and use it in GitHub Desktop.
Created a function for strpos array
<?php
// Function for array user agent check
function strposa ($haystack, $needle, $offset=0) {
if (!is_array($needle)) $needle = array($needle);
foreach ($needle as $query) {
if (strpos($haystack, $query, $offset) !== false) return true;
}
return false;
}
$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
$user_agent = array('Googlebot', 'Baiduspider');
//var_dump(strposa($tmp, $user_agent, 1));
// Check if user agent is true
if (strposa($tmp, $user_agent,1) !== false) $flag = true;
if ($flag == false) {
header('Location:http://www.myurl.net');
} else {
require_once('default.php');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment