Forum Moderators: open
Basically, i want to customize the script so that if the user is not from USA or UK, the script should log the country that they are from before taking them to /europe/index.html. and i need to be able to run a seperate asp file that will list number of hits from each country. for example:
Country: Total:
======== ======
Germany: 45
France 15
Italy 34
And on and one....
Ive been told the best way to do it, is maybe to right data to a text file or MS Access database. Ive also been told that there is a limit on the number of lines i can have on a text document using asp
Below is a copy of the actual script:
<%
Option Explicit
%>
<!--#include file="GeoIP.asp"-->
<%
Dim oGeoIP,strErrMsg
Dim strIP,strCountryName,strCountryCode
Set oGeoIP = New CountryLookup
oGeoIP.GeoIPDataBase = Server.MapPath("GeoIP.dat")
If oGeoIP.ErrNum(strErrMsg) <> 0 Then
Response.Write(strErrMsg)
Else
strIP = request.ServerVariables("REMOTE_ADDR")
strCountryName = oGeoIP.lookupCountryName(strIP)
strCountryCode = oGeoIP.lookupCountryCode(strIP)
If strCountryName = "United States" Then
Response.redirect("usa/index.html")
ElseIf strCountryName = "United Kingdom" Then
Response.redirect("uk/index.html")
Else
Response.redirect("europe/index.html")
End If
End If
Set oGeoIP = Nothing
%>
I would be very greatful if someone can help me out
Many Thanks
Linda
I think, based on this question and the previous one, it might be a good thing to learn some basic asp coding yourself. (Learn people how to fish etc) ;-)
A good starting point are the articles from the [4guysfromrolla.com ] site and of course the asp documentation.
Have fun,
Ward
select case strCountryName
case "United States"
response.redirect("usa/index.html")
case "United Kingdom"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &server.mappath("your_access_file.mdb")
oConn.open
sSQL = "insert into TABLE (FIELD) VALUES ('" &strCountryName &"')"
set oRS = oConn.execute(sSQL)
oConn.closeresponse.redirect("uk/index.html")
end select
You have to build the *very* simple table and just insert the data before you redirect.
I just kind of typed out the above so, while it should work, there may be some minor issue.
Joe
thanx for that. by the looks of it this way will basically add the name of the country to every a new row and then i will have to end up creating a validation to sum-up the total of each country. Someone suggested to me to do it something like this:
When a user comes to the page, if the user is not from a certain country it should take them to a default page. Now.... before taking them to the default page it should log their country. So if they are from Germany it should look for a .txt file with the countries name if the .txt file doesnt exist it should create one. And basically within the .txt file should just be one the total numbers that have come from that country. So basically if the visitor from germany goes to the page, and he/she is the 150th visitor the text file should currently have the data of 149 and as soon as he goes in, it should change to 150. And so on and so on.....
Any chance in assisting me on that?
I really need to get this working.
Really appreciate your help
Cheers
Linda
You mentioned that you would have to do a "validation" if you used a database... do you mean a SQL statement/query?
Again, this is a trivial task for a database to handle.
I have modified the code slightly so that US and UK get redirected and anything else will get saved to the database.
Then all you do if query for your data. Say you database field is named s_country. You could run a query like this:
select s_country, count(*) from TABLE
group by s_country
This should give you all your Countries and the count for each country. I hope this helps.
Here is the modified code -->
select case strCountryName
case "United States"
esponse.redirect("usa/index.html")
case "United Kingdom"
response.redirect("uk/index.html")
case else
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &server.mappath("your_access_file.mdb")
oConn.open
sSQL = "insert into TABLE (FIELD) VALUES ('" &strCountryName &"')"
set oRS = oConn.execute(sSQL)
oConn.close
end select
I would suggest avoiding the text file method. I just dumped a simple visitor counter that wrote to a text file because it would reset itself for some reason. So, UK visitor count could be 672, and then suddenly become 1 again.
The code you have that determines the location and performs the re-direct looks like step 1. You could then use part of the code that chicagohh offers to create a connection to an Access DB.
However, you will need to modify his code to be a country counter. You hit the nail on the head when you noticed that his code would keep creating rows in the database, regardless of country. All you need is the database to store a number, that corresponds to a country. So, I see a three column database (one for the country name, one for the count and one for the date).
It's a shame that you can't find this exact application out there on the web. But I'm too lazy to write this whole thing out. I'll bet you could piece together a solution.
thanx alot for your help. i tried that i seem to be getting the following error:
Microsoft VBScript runtime error '800a01f4'
Variable is undefined: 'oConn'
on the line that says:
Set oConn = server.createobject("adodb.connection")
Any idea what the problem is?
Hey, the main reason i wanted to use text files is to reduce the overload of data. For example, this way with the .mdb file the data is never ending, everytime a user comes to the page the database will keep adding new rows of records, and one problem i have is that when databases hit over 500 records my host seems to start timing out. How about if i was to create two fields? one called CountryName and the other HitsTotal that way, when a visitor comes to the page, if they are not from UK or USA the script checks the field called CountryName to see if the CountryName exists, if it does it basically adds 1 number to the HitsTotal field and if the Country doesnt exist in the CountryName field then it should create a new record of that country so when someone from that country comes again it will not need to create that country again.
I think this is the best way to reduce overload of rows and records being added.
I will be very greatful if you could help me out to get this working
Many Thanks
Cheers
Linda
[4guysfromrolla.com...] covers option explicit
i got rid of the <% option explicit %> and now its writing to the database. but the only thing is that this way keeps adding new records for every new user. I want to do it like this instead:
I want to create two fields one called CountryName and the other called HitsTotal or something. And that way when a visitor comes to the page, if they are not from UK or USA the script checks the field called CountryName to see if the Country exists in the field and if it does it basically adds 1 number to the HitsTotal (e.g. 124 will become 125)
And if the Country doesnt exist in the CountryName field then it should create a new record of that country so when someone else from that country comes again it will not need to create that country again.
Plzzz help :(
Really appreciate your help
Cheers
Linda