Page 1 of 1

how to include the right php by checking the ip

Posted: Thu Nov 25, 2004 3:55 am
by sean82
hi
i need a script that includes a file.php only if the user is from germany and if not (if the user has other ip) it includes the other file2.php
is this possible?
can u help
thx

Posted: Thu Nov 25, 2004 4:41 am
by rehfeld
well, you would need a database which lists which ips are from which country

then just check thier ip and base your descision upon which country the ip correlates to.

geoip has one for free i beleive.


but still, there will always be ips that will be identified incorrectly. it think geoip claimed high 90% accuracy but i think you can do better in this situation. this would also add a lot of load to the server, having to query the db so many time from such a large set of data



i beleive most browsers send an HTTP_ACCEPT_LANGUAGE header for this purpose

Code: Select all

if (isSet($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $accept = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
    if (false !== strpos($accept, 'de')) {
        // include german.php
    } elseif (false !== strpos($accept, 'en')) {
        // english
    } else {
        // default
    }
} else {
    // default
}

Posted: Thu Nov 25, 2004 5:17 am
by sean82
this is a great idea but how does it work
i used this but nothing was included just an empty screen

Code: Select all

<?
if (isSet($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {  
  $accept = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);   
   if (false !== strpos($accept, 'de')) {      
     // include default.php 
        } elseif (false !== strpos($accept, 'en')) {     
           // include navigation.php  
             } else {     
                // default   
                 }
                } else {   
                 // default
                 }
           ?>