The Initialize method is used to obtain country information for a specific IP address. For example, if you want to obtain country information for a visitor with the IP address of 207.46.230.220, you would call the Initialize method and pass in this IP address.
Syntax:
chObj.Initialize ipAddrAsStr
Example:
<html>
<% set chObj = CreateObject("cyScape.countryObj")
chObj.Initialize "207.46.230.220"
response.write "The country for 207.46.230.220 is " & chObj.CountryCode %>
</html>
Tip: If you wish to detect country information from an ASP page for the current site visitor under ASP or ASP.NET, there is no need to call the Initialize method. In this case you should use Server.CreateObject instead of CreateObject under ASP, and the GetCountry method under ASP.NET. When you use Server.CreateObject, CountryHawk automatically obtains the IP address for the current visitor and calls the Initialize method for you behind the scenes.
For example, assume you wanted to log the country code from an ASP page for the current visitor. You would use this code instead of the code above:
set chObj = Server.CreateObject("cyScape.countryObj")
response.write "Your country code is: " & chObj.CountryCode
Those two lines of code are equivalent to the following (and more convenient):
set chObj = CreateObject("cyScape.countryObj")
chObj.Initialize Request.ServerVariables("REMOTE_ADDR")
response.write "Your country code is: " & chObj.CountryCode
Note: If you are using ColdFusion, or another scripting language other than ASP or ASP.NET, you need to obtain the IP address using the methods provided by that scripting language and call the Initialize method yourself. This is because ASP and ASP.NET are the only scripting language that provides access to the HTTP context, which is needed for the automatic initialization. See a ColdFusion example for details.
If you are using ASP, the Initialize method is optional and typically used if you wish to obtain country information for an IP address other than that of the current visitor. Likewise under ASP.NET you can use the GetCountry method of the CountryObj class if using the native .NET version of CountryHawk.
For example, if you are processing a log file or obtaining an IP address at run-time from a source other than the current visitor's browser. If you are not using ASP or ASP.NET, then this method is required in order to initialize the component based on a specific IP address (either that of the current visitor or one obtained programmatically at run-time).
Note: If ipAddAsStr is not a properly formatted IP address (xxx.yyyy.zzz.aaa), CountryHawk will raise a run-time error. Therefore unless you are certain the IP address is in a valid format, you should either check to be sure using the isValidIP method, or use "on error resume next" and check for errors following the call to the Initialize method.
Tip: See the ch_initialize.asp sample for more information.
See Also:
About the Properties and Methods Guide