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
how to include the right php by checking the ip
Moderator: General Moderators
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
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
}this is a great idea but how does it work
i used this but nothing was included just an empty screen
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
}
?>