Reputation: 512
ok I'm using geoio.com to find out a users location, I get back a load of info based on this bit of code
<?php $_SESSION['geo'] = file_get_contents("http://api.geoio.com/q.php?key=********=geoip&d=comma&q=" . getenv('REMOTE_ADDR') . ""); ?>
The above set's the session variable to
Chesterfield,Derbyshire,United Kingdom,Greenfrog Computing Ltd Managed Broadband Adsl Ass,53.2500,-1.4167,GB)
So all I want to do, is if that session variable contains United States , is redirect users to a different URL called /us/
How do I 'find' the United States bit and act on it.
Any help greatly appreciated ! (note I edited out the API key)
Cheers
Rich :)
Upvotes: 0
Views: 75
Reputation: 6003
Try this:
Assume your session variable is location.
<?php
$_SESSION['location'] = 'Chesterfield,Derbyshire,`United States`,Greenfrog Computing Ltd Managed Broadband Adsl Ass,53.2500,-1.4167,GB';
$tmp = explode( ',', $_SESSION['location'] );
$string_to_search = 'United States'
$key = array_search( $string_to_search, $tmp );
if($key !== false) {
// go to `us` folder
}
?>
Hope it helps.
Upvotes: 0