I have built a web site for a client that has a database of products that are available in New Zealand and Australlia. The prices differ for both countries. In addition, there is a part of the site that is available only to dealers which, amongst other things, contains wholesale pricing info.
The task that I was given was to only display the retail and wholesale pricing for the country from which visitors originate. This is the solution:
/*Firstly, get the IP address of the visitor*/
$E=getenv(REMOTE_ADDR);
/*Secondly, get the Host Name*/
$F=getHostByName($E);
/*
Then convert the Host Name, suppressing error messages in case there is
no reverse lookup available for the IP address
*/
$G=@getHostByAddr($F);
/*
Use a regular expression to ascertain whether the last characters of the
Address - $G - fits the pattern, and if it does then assign it to the
variable, $price
*/
if(ereg(".au$",$G)){
$price = aust_price;
}else{
$price = nz_price;
}
/*Then construct a query*/
$query = "select name, description, prod_id, ";
$query .= $price;
$query .=", image, category from product where category like '$category%'";
$result = mysql_query($query);
I hope that this is of help to some people.
Regards
Martin cameron