Skip to main content
Inspiring
September 3, 2006
Answered

cgi.remote_addr and cgi.remote_host and hit counter

  • September 3, 2006
  • 1 reply
  • 437 views
Hi,
I am a beginner. Borrowed and modified script for a counter as well as some statistics. Everything works fine except that the IP address of the visitor always shows as 216.251.42.XX . I've tried to have friends access the site from all over just to check if I get a different IP address but its still 216.251.42.XX

I wonder if someone can advise me on where I am going wrong.
Thank you in advance.
THE CF SYNTAX BEING USED BY ME AS FOLLOWS:
<cfquery name="updateHits" datasource="#RequestDSN#">
UPDATE hit_counter SET hit_count = hit_count + 1
</cfquery>
<CFIF isdefined("Cookie.user_id")>
<CFSET user_id=trim(Cookie.user_id)>
<CFELSE>
<CFSET user_id="">
</CFIF>
<cfset currentdate = #DateFormat(Now(), "dd mmm yy")#>
<cfset currenttime = #TimeFormat(Now(), "hh:mm:ss")#>
<CFSET address = cgi.remote_addr>
<CFSET host = cgi.remote_host>
<CFSET referer = cgi.http_referer>
<CFSET agent = cgi.http_user_agent>
<CFSET page = cgi.script_name>
<CFIF NOT Len(host)>
<CFSET host = "unknown">
</CFIF>
<CFIF NOT LEN(referer)>
<CFSET referer = "unknown">
</CFIF>
<cfquery name="userstats" datasource="#RequestDSN#">
INSERT INTO stats (VISITDATE, VISITTIME, ADDRESS, HOST, REFERER, AGENT, PAGE)
VALUES ('#currentdate#', '#currenttime#', '#address#', '#host#', '#referer#', '#agent#', '#page#')
</cfquery>
This topic has been closed for replies.
Correct answer jasan3114
Solved my problem: Should use the cfif statement below instead of just the cfset address = cg.remote_addr
<CFIF #CGI.HTTP_X_Forwarded_For# EQ "">
<CFSET address="#CGI.Remote_Addr#">
<CFELSE>
<CFSET address="#CGI.HTTP_X_Forwarded_For#">

1 reply

jasan3114AuthorCorrect answer
Inspiring
September 3, 2006
Solved my problem: Should use the cfif statement below instead of just the cfset address = cg.remote_addr
<CFIF #CGI.HTTP_X_Forwarded_For# EQ "">
<CFSET address="#CGI.Remote_Addr#">
<CFELSE>
<CFSET address="#CGI.HTTP_X_Forwarded_For#">