mercredi 6 juillet 2016

PHP If And - Country / Mobile or not mobile includes

Hoping someone can help me out with this. I'm trying to include a file based on country and if mobile or not.

Here is the code I'm using to check if the device is mobile or not:

$_SERVER['HTTP_USER_AGENT'];

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],"iPad");

if ($iphone || $android || $palmpre || $ipod || $ipad || $berry == true) 

{ 
include("mobile.php");
}

else {
include("desktop.php");
}

Here is the code I'm using to check location and redirect:

require_once('geo/geoip.inc');
$gi = geoip_open('geo/GeoIP.dat', GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

if ($country == 'FR') { 
header('Location: fr.php');
}

elseif ($country == 'BE') { 
header('Location: be.php');
}

elseif ($country == 'CA') { 
header('Location: ca.php');
}

elseif ($country == 'CH') { 
header('Location: ch.php');
}

else {

}

Instead of redirecting, I want to include. So, if mobile and location is FR, i would include("mobilefr.php"); - Not mobile would include desktopfr. Same goes for the other countries and default (or no country listed) would be mobile.php and desktop.php

I've tried doing it myself but keep getting stuck / errors.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire