Jump to content

Country Currency Detection HELP!


Recommended Posts

Hey Guys

I been reading that you can detect peoples countrys ip and have it redirect to a different URL depending what there country is for example shop.us shop.uk for us or united kingdom IP's

I've read this is possible by adding IP CSV to the database and then having the PHP code to handle the url change.

The code which I have obtained is as follows

<?php 
// Replace this MYSQL server variables with actual configuration 
$mysql_server = "mysql_server.com"; 
$mysql_user_name = "UserName"; 
$mysql_user_pass = "Password"; 

// Retrieve visitor IP address from server variable REMOTE_ADDR 
$ipaddress = getenv(REMOTE_ADDR); 

// Convert IP address to IP number for querying database
$ipno = Dot2LongIP($ipaddress); 

// Connect to the database server 
$link = mysql_connect($mysql_server, $mysql_user_name, $mysql_user_pass) or die("Could not connect to MySQL database"); 

// Connect to the IP2Location database 
mysql_select_db("IP2Location") or die("Could not select database"); 

// SQL query string to match the recordset that the IP number fall between the valid range 
$query = "SELECT * FROM IPCountry WHERE $ipno < = ipTO AND $ipno>=ipFROM"; 

// Execute SQL query 
$result = mysql_query($query) or die("IP2Location Query Failed"); 

// Retrieve the recordset (only one) 
$row = mysql_fetch_object($result); 

// Keep the country information into two different variables 
$countrySHORT = $row->countrySHORT; 
$countryLONG = $row->countryLONG; 

// Free recordset and close database connection 
mysql_free_result($result); mysql_close($link); 

// If the visitors are from JP, redirect them to JP site 
if ($countrySHORT == "JP") 
{
 Header("Location: http://www.google.co.jp"); 
} else { 
// Otherwise, redirect them to US site 
 Header("Location: http://www.google.com");
}
exit;

// Function to convert IP address (xxx.xxx.xxx.xxx) to IP number (0 to 256^4-1) 
function Dot2LongIP ($IPaddr) { 
if ($IPaddr == "") 
{
  return 0;
} else { 
  $ips = split ("\.", "$IPaddr"); 
  return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256); 
}
} 
?> 



Now putting this in is str8 forward enough but I dont want it to proform a url change instead I want to change currency.. ie javascript commands

javascr1pt:setCurrency(1);
javascr1pt:setCurrency(2);
javascr1pt:setCurrency(3);

Please note that the 1 in script was added because these forums automaticly remove the sting.

Can anyone change the php code for me since I dont know enough to be able to do it, im sure its pretty str8 forward so instead of url change, it does [removed]setCurrency(2); [removed]setCurrency(1) etc etc

Please help, thanks in advance

Link to comment
Share on other sites

×
×
  • Create New...