dombrorj Posted October 29, 2010 Share Posted October 29, 2010 Hi, I'm trying to get a working php script that will redirect visitors based on a number of variables. I first want to check the country the visitor is from, and redirect based on the user's country ip address. If visitor is not from the US, then go to google.com (for example)... but only after also checking some other variables. I want to also redirect any user (including US visitors) who are using a mobile device browser/cell phone, and redirect visitors coming from a Linux box. I'm not sure how to add those as if/else statement. Any help would be appreciated. Here's what I have so far... Geo ip Redirect: ------------------- <?php require_once("GeoIP.inc"); $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if($country_code == 'US') { header('Location: http://www.google.com'); } else { header("Location: http://www.redirect.com"); } ?> Mobile Browser Redirect: ------------------------------ require_once('mobile_device_detect.php'); mobile_device_detect(true,false,true,true,true,true,true,'http://redirect.com',false); So not sure how to detect and redirect Linux users, and then how to link these all together in one script so it checks all variables before sending user to destination URL. Hope you can help. I really appreciate it! Link to comment https://forums.phpfreaks.com/topic/217180-redirect-based-on-os-ip-and-browser/ Share on other sites More sharing options...
Anti-Moronic Posted October 29, 2010 Share Posted October 29, 2010 Not sure on the specifics but with extensive if/else statements. Consider 'switch()' instead. Like so: switch($country_code){ case 'US': header() etc break; case 'UK': break; } Makes your code far more easier to manage. You could put inside an object which would make it super easy to build and maintain. At very least, wrap everything in a function. Link to comment https://forums.phpfreaks.com/topic/217180-redirect-based-on-os-ip-and-browser/#findComment-1127900 Share on other sites More sharing options...
dombrorj Posted October 29, 2010 Author Share Posted October 29, 2010 Thanks for the tip. But, to be honest, sounds like I'm way over my head. I'd be willing to pay a few bucks for your time if you're able to help me put this together. I can give you more detail over PM if interested? Link to comment https://forums.phpfreaks.com/topic/217180-redirect-based-on-os-ip-and-browser/#findComment-1127903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.