You're mis-using strpos()
, as explicitly warned on its document page: http://php.net/strpos
strpos() can and WILL return a legitimate 0
if the string you're searching for is at the START of the string being searched. But PHP will interpret that 0
as a false (aka failure), which is you're getting your bad redirects.
You have to use the strict comparison operators, e.g.
if (strpos($UA, 'facebook') !== false) {
^^^---strict operator, note the extra `=`.
which test the variable's type AND value, not just the value. strpos will return a boolean FALSE if no match is found, but PHP treats
(false == 0)
as true, wherease
(false === 0) // note the extra =
is false.