Ekibyo Posted June 12, 2012 Share Posted June 12, 2012 so here the thing, im trying to make a redirect by ip for my website, so i found this, and with a little twitch i made it work <?php require_once('geoip.inc'); $gi = geoip_open('GeoIP.dat', GEOIP_MEMORY_CACHE); $country = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); $my_countries = array('us', 'ca'); //Esas son las ips de USA y CANADA se pueden aplicar mas librerias segun otros paises ejemplo Fr para FRANCIA etc.. if (!in_array(strtolower($country), $my_countries)) { header('Location: http://www.tigo.com.hn/'); //Paginas de Honduras y el Mundo menos USA y CANADA } else { ob_start(); echo "en 10 segundos sera redireccionado a la pagina internacional, desea cancelar haga , <a href='http://www.tigo.com.hn/'>click aqui"; header('Refresh: 10; URL=http://www.tigo.com.hn/seccion/recargas-internacionales') ; ob_flush(); } ?> but in some IE Browsers dont work, just dont redirect. i fix it putting and exit(); after the header and it works but the page dont load. i am only getting the message if i wanna redirect in a blank page. :'( so what do i want i want a redirect that works in every browser. and load the page full with the message i dont know what am i doing wrong thnx for the help Quote Link to comment https://forums.phpfreaks.com/topic/264056-another-header-location-problem-with-ie/ Share on other sites More sharing options...
Psycho Posted June 12, 2012 Share Posted June 12, 2012 Per the manual you can't send output to the browser before a header(). I don't think you can use ob_start() to get around this and don't know why you would even try. So, put the echo after the header(). The header takes 10 seconds to take effect so there is plenty of time to display the output. if (!in_array(strtolower($country), $my_countries)) { header('Location: http://www.tigo.com.hn/'); //Paginas de Honduras y el Mundo menos USA y CANADA } else { header('Refresh: 10; URL=http://www.tigo.com.hn/seccion/recargas-internacionales') ; echo "en 10 segundos sera redireccionado a la pagina internacional, desea cancelar haga , <a href='http://www.tigo.com.hn/'>click aqui</a>"; } Quote Link to comment https://forums.phpfreaks.com/topic/264056-another-header-location-problem-with-ie/#findComment-1353217 Share on other sites More sharing options...
Ekibyo Posted June 12, 2012 Author Share Posted June 12, 2012 i dont know why... but some minutes ago wasnt working without the ob_start(); ob_flush(); and now its working... how can i test this if its is working with all the IE browser versions.? and thnx for the help Quote Link to comment https://forums.phpfreaks.com/topic/264056-another-header-location-problem-with-ie/#findComment-1353221 Share on other sites More sharing options...
Psycho Posted June 12, 2012 Share Posted June 12, 2012 i dont know why... but some minutes ago wasnt working without the ob_start(); ob_flush(); and now its working... Well, if you had the header() and echo swapped as you did previously I would expect it to fail. The code I posted had those two lines and I would expect them to work. how can i test this if its is working with all the IE browser versions.? Um, test it with the browser versions you want to verify against? You'll would probably want to set up virtual machines with the appropriate Operating Systems and browser versions. But, in this case I would test against the oldest version you want to support and the newest version of each browser. It's not perfect, but unless you have a team of testers it makes the most sense. Quote Link to comment https://forums.phpfreaks.com/topic/264056-another-header-location-problem-with-ie/#findComment-1353331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.