PHPBuilder - Display database info based on visitor's origin



RSS Twitter
Tips Tricks And Hacks

Display database info based on visitor's origin

by: Martin Cameron
|
August 5, 2000

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

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Martin Cameron

Comment:



Comment:

(Maximum characters: 1200). You have characters left.