BrowserHawk IQ now available! Click here for the full scoop!
Search:
How can I simulate CountryHawk results to check program logic?
Created: 6/3/2003    Updated: 6/3/2003
Q   How can I simulate CountryHawk results to check program logic? For example, I want to test how my script behaves when CountryHawk detects a visitor from Japan. But I don't have any way to have my page accessed from a visitor in Japan I can test with.

A   By default CountryHawk detects the country of origin based on the current visitor's IP address. Most likely this is how your script is coded, as recommended.

With this in mind there are two ways to simulate CountryHawk results.

The first way is to insert a line of code which forces CountryHawk to use an IP address known to be related to the country you want to simulate access for.

Example - ASP with CountryHawk for ActiveX/COM:
   set chObj = Server.CreateObject("cyScape.CountryObj")
   'To simulate for a specific country, add the following line
   chObj.Initialize("some.ipaddress.goes.here")

Example - C# with CountryHawk for .NET:
   // Comment out one of the following depending on whether you are testing

   // For real-world usage
   // CountryObj chObj = CountryObj.GetCountry();

   // For testing a specific country
   CountryObj chObj = CountryObj.GetCountry("some.ip.goes.here");

The above approach is a bit cumbersome, but it has the advantage that it let's you test that CountryHawk actually will recognize a specific IP address as being assigned to a country so you can gague its accuracy.

The second way to simulate a specific country is easier and cleaner. In this case just use CountryHawk to detect the country code as normal. Then change your code to reference the country code out of the variable instead of directly out of the object itself. To simulate a specific country, just insert a line to force the variable to a specifc result you want to test.

Example:
   set chObj = Server.CreateObject("cyScape.CountryObj")
   countryResult = chObj.Country
   ' Force to a specific result for testing, remove for production
   countryResult = "JP"
   if countryResult = "JP" then
      ...
   end if
With the above approach, you can just hard code the countryResult variable to any country code you wish to test your logic for. Just be sure to remove the hard coded result prior to using the code in production.

    FAQ Home  |  Search FAQ  |  Show New Items  |  Ask a FAQ  |  Notify Me  |  Most Popular     
 
 
Copyright © 1994-2020 cyScape, Inc. All Rights Reserved. ()
ASP, ASP.NET, ColdFusion MX, CFMX, JSP, PHP