Forum Moderators: open
I'm no programmer and php/asp fazes me. I can post asp code in a htm page (but don't want to rename the pages to asp or put redirect tags in each htm page header to point to an asp equivalent). I can also create include pages (SSIs) or iframes (I am very familiar with FP itself).
I raised this question in website technologies forum [webmasterworld.com] and encyclo kindly posted some PHP code that does this job and the suggestion was that someone here could give me the asp equivalent (no PHP support at this hosting service despite a price of £800 per year... but for various reasons can't move the site elsewhere just yet)
<?php
if (strpos($_SERVER["HTTP_ACCEPT_LANGUAGE"], 'en-gb')!== FALSE) {
include 'gb-aff-code.inc'; // include for GB customers
}
else {
include 'us-aff-code.inc'; // include for the others
}?>
Anyone with any ideas or suggestions? I'd like to get into learning PHP or asp but just don't have the time. As a small business owner the webmaster hat is only one of very many hats I wear.
[ip-to-country.webhosting.info...]
Download this, uncompress it and create a new table in your database. Call it something like ip_country.
Then put all the data from the file into this table. You should have 5 fields, IP_FROM, IP_TO, COUNTRY_CODE2, COUNTRY_CODE3, COUNTRY_NAME
OK, you can write some ASP now. Paste the following into a new file and call it ipaddressconvert.asp
<%
DottedIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if DottedIP = "" then
DottedIP = Request.ServerVariables("REMOTE_ADDR")
end if
If DottedIP = "" Then
Dot2LongIP = 0
Else
For i = 1 To 4
pos = InStr(PrevPos + 1, DottedIP, ".", 1)
If i = 4 Then
pos = Len(DottedIP) + 1
End If
num = Int(Mid(DottedIP, PrevPos + 1, pos - PrevPos - 1))
PrevPos = pos
Dot2LongIP = ((num Mod 256) * (256 ^ (4 - i))) + Dot2LongIP
Next
End If
%>
This basically gets a users ip address, then converts it into a long number that the database uses to look up the location.
Right, on the page you want to do a country lookup put in the following code:
<!--#include virtual="/ipaddressconvert.asp" -->
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "PROVIDER=MSDASQL; DRIVER={SQL Server}; SERVER=localhost;DATABASE=location;UID=username;PWD=password;"
slocSQL = "SELECT COUNTRY_CODE3 FROM ip_country WHERE " & Dot2LongIP & " BETWEEN IP_FROM AND IP_TO"
Set RsLoc = Conn.Execute(slocSQL)
check_country = Trim((RsLoc.Fields("COUNTRY_CODE3").value))
IF RsLoc.EOF THEN
%>
<!--#include virtual="/your-other-file.asp" -->
<%
ELSE
IF check_country = "GBR" THEN
%>
<!--#include virtual="/your-uk-file.asp" -->
<%
ELSE
%>
<!--#include virtual="/your-other-file.asp" -->
<%
END IF
END IF
%>
What this does is connects to the database, looks up the users IP address and returns a country code for it. If the code = GBR (great britian) includes your uk file, otherwise it returns your generic file. You can use this to customise for any country in the database.