PDA

View Full Version : how to include the right php by checking the ip


jemand
11-25-2004, 10:01 AM
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

Fou-Lu
11-25-2004, 10:18 AM
Technically, you could identify what thier ISP location is, and direct it from there. You have some problems with this though, take my ip sometimes it shifts to some place in virginia, though I live in Canada. So you cannot really rely on that too much. Next to that, you would need to find out what all of the locations are in germany, and how it reflects on their IP address. Which I'm sorry to say I don't know where to find, a google could probably process that for you.
However, I would say there has to be another way around this. Using just php, I couldn't guarentee it, but I know it can be done in some other means.

The larger question is, does anyone know of a reliable way to go abouts doing this?

raf
11-25-2004, 11:24 AM
you can download a free IP to country db.
the 'problem' with that conversion is that this gives you the location of the ISP, which can be different from the users one.

A fairly complete discussinon here :
http://www.codingforums.com/showthread.php?t=31432&highlight=country

jemand
11-25-2004, 12:23 PM
hi
i tried a get language process
with this
<?
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

?>
but it doesnt work
whats wrong

Fou-Lu
11-25-2004, 02:41 PM
I've never used an automatic setup, so this may not work. Also remember, that HTTP_ACCEPT_LANGUAGE comes in more than one format, it will assume that if a language is mentioned first, that its the common language, while any following it are alternatives. So, de,en-us would say german first, us english after.
Its worth a shot:

<?php

if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
// Probably shouldn't be empty anyway...
$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (strpos(" " . $language, "de") > 0)
{
// Include your german here. Whether it be an include or code.
}
else
{
/* I recommend using your english here. I wouldn't use an else if because it will limit what you need. */
}
}
else
{
// More english perhaps?
}
?>


Now, this code will (should) redirect as long as de appears in the language. If you want to only send if the users primary shows as de, use:

if (substr($language, 0, 2) == "de")
// Instead of:
if (strpos(" " . $language, "de") > 0)


Let me know if that works, yeah?

jemand
11-25-2004, 03:52 PM
ya this works with some changes
finally it looks this
<?
if (substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2) == "de"){
include 'shop/germany/shop.php';
}else{
include 'shop/us/shop.php';
}
?>