<tr>
<td width="80" align=right style="font-size:12px">您的IP:</td>
<td width="420">
<input name="ip" type="text" disabled=false class="input" id="ip" value="<%=Request.ServerVariables("Remote_HOST")%>" size=30 maxlength=60>
</td>
</tr>
这样可以将IP自动获取,那么我想在用户提交留言的时候把这个获取到得IP地址写入到数据库中怎么写?
我这样写(其中两行代码我在下面用//*****标出),但其他内容都写入到了数据库中,唯独数据库中IP字段的内容是空的。不知道哪里错了还是?请各位帮帮忙。谢谢!我写的代码如下:
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=Request.ServerVariables("Remote_HOST")//****************
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip //**************
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
11 个解决方案
#1
获取IP的函数
调用方法IP=getIP()就行了,Try!
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
调用方法IP=getIP()就行了,Try!
#2
引楼上方法
ip=Request.ServerVariables("Remote_HOST")//****************
更
IP=getIP()
ip=Request.ServerVariables("Remote_HOST")//****************
更
IP=getIP()
#3
好像没用啊,查看了下,IP字段内容还是空的。啥都没有。是不是我弄错了还是?调用的获取IP函数的代码放的位置有限制吗?请帮我再细说下,可以不?
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
#4
那你要保证你的if 语句为真了,它才会执行下去呀,完整的你是怎样写的呀!?
#5
<%
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
%>
<%if sendok=0 then%>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="CENTER" valign=top style="line-height:200%;font-size:12px">
<form name="form" method="post" action="<%=linkcontact%>?id=<%=id%>" onsubmit="return checkinput(form)" autocomplete = "off">
<tr>
<td width="80" align=right style="font-size:12px">标题:</td>
<td width="420">
<input type="text" name="subject" maxlength=60 size=40 class="input" value=<%=subject%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">邮箱号码:</td>
<td width="420">
<input type="text" name="from" maxlength=60 size=40 class="input" value=<%=from%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的姓名:</td>
<td width="420">
<input type="text" name="name" maxlength=60 size=20 class="input" value=<%=name%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">单位:</td>
<td width="420">
<input type="text" name="company" maxlength=60 size=40 class="input" value=<%=company%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">地址:</td>
<td width="420">
<input type="text" name="address" maxlength=60 size=40 class="input" value=<%=address%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">电话:</td>
<td width="420">
<input type="text" name="telphone" maxlength=60 size=40 class="input" value=<%=telphone%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">传真:</td>
<td width="420">
<input type="text" name="fax" maxlength=60 size=30 class="input" value=<%=fax%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的IP:</td>
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value=<%=getip()%>>
</td>
</tr>
<tr>
<td align=right style="font-size:12px">内容:</td>
<td>
<textarea rows=10 cols=50 name="body" style="font-family:宋体" class="input"><%=body%></textarea><br><font color="#00CC00">*建议填写</font>
</td>
</tr>
<tr>
<td align=center height=30 valign=middle> <br>
</td>
<td height=30 valign=middle>
<input type="image" border="0" name="imageField2" src="images/contact/bt_sendc.gif" width="40" height="18">
<img border="0" name="imageField2" src="images/contact/bt_resetc.gif" width="40" height="18" onclick="javascript:document.form.reset();document.form.subject.focus()" style="cursor:hand;">
</td>
</tr>
</form>
可以看下这些代码吗?我是这样弄的,IF语句应该是真的吧,其他的文本框中的数据都成功添加到数据库中了,只有IP字段的是空的。
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
%>
<%if sendok=0 then%>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="CENTER" valign=top style="line-height:200%;font-size:12px">
<form name="form" method="post" action="<%=linkcontact%>?id=<%=id%>" onsubmit="return checkinput(form)" autocomplete = "off">
<tr>
<td width="80" align=right style="font-size:12px">标题:</td>
<td width="420">
<input type="text" name="subject" maxlength=60 size=40 class="input" value=<%=subject%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">邮箱号码:</td>
<td width="420">
<input type="text" name="from" maxlength=60 size=40 class="input" value=<%=from%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的姓名:</td>
<td width="420">
<input type="text" name="name" maxlength=60 size=20 class="input" value=<%=name%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">单位:</td>
<td width="420">
<input type="text" name="company" maxlength=60 size=40 class="input" value=<%=company%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">地址:</td>
<td width="420">
<input type="text" name="address" maxlength=60 size=40 class="input" value=<%=address%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">电话:</td>
<td width="420">
<input type="text" name="telphone" maxlength=60 size=40 class="input" value=<%=telphone%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">传真:</td>
<td width="420">
<input type="text" name="fax" maxlength=60 size=30 class="input" value=<%=fax%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的IP:</td>
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value=<%=getip()%>>
</td>
</tr>
<tr>
<td align=right style="font-size:12px">内容:</td>
<td>
<textarea rows=10 cols=50 name="body" style="font-family:宋体" class="input"><%=body%></textarea><br><font color="#00CC00">*建议填写</font>
</td>
</tr>
<tr>
<td align=center height=30 valign=middle> <br>
</td>
<td height=30 valign=middle>
<input type="image" border="0" name="imageField2" src="images/contact/bt_sendc.gif" width="40" height="18">
<img border="0" name="imageField2" src="images/contact/bt_resetc.gif" width="40" height="18" onclick="javascript:document.form.reset();document.form.subject.focus()" style="cursor:hand;">
</td>
</tr>
</form>
可以看下这些代码吗?我是这样弄的,IF语句应该是真的吧,其他的文本框中的数据都成功添加到数据库中了,只有IP字段的是空的。
#6
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这一段的IP有没有显示出来呢,如果有的话(应该是有的吧)那是你其他地方的错误啦
不知道你的代码为什么没有end if,而且sendOK=0的条件下,既是写进数据库,又是显示填写表单,而表单里的action也并不是提交到本页的
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这一段的IP有没有显示出来呢,如果有的话(应该是有的吧)那是你其他地方的错误啦
不知道你的代码为什么没有end if,而且sendOK=0的条件下,既是写进数据库,又是显示填写表单,而表单里的action也并不是提交到本页的
#7
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这里在点留言时,文本框中是显示出来了IP地址。但就是点提交后没写入到数据库中。end if 代码上有的,刚才贴的时候忘贴上去了,action是提交到本页的,只不过换了种链接方式。其他文本框里面的内容都是可以成功写入到数据库里面去的。但惟独这个IP写不到数据库的IP字段里面去。我两个地方写对了吗(下列我用//*******标示的)?
<%
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email <>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP() //******************************
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip //******************************
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
end if
end if
%>
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这里在点留言时,文本框中是显示出来了IP地址。但就是点提交后没写入到数据库中。end if 代码上有的,刚才贴的时候忘贴上去了,action是提交到本页的,只不过换了种链接方式。其他文本框里面的内容都是可以成功写入到数据库里面去的。但惟独这个IP写不到数据库的IP字段里面去。我两个地方写对了吗(下列我用//*******标示的)?
<%
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email <>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP() //******************************
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip //******************************
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
end if
end if
%>
#8
对的啊,暂时没发现错误,这可就奇迹了哦
数据库里的类型是文本吧
可是如果有错误应该是会报错的呀,呵呵,神奇!
数据库里的类型是文本吧
可是如果有错误应该是会报错的呀,呵呵,神奇!
#9
是啊,晕了哦。数据库IP字段类型是文本型的。也没报什么错,其他的内容都成功写入到数据库中了,惟独这个IP没写进去。真是晕了哦。一般放IP的字段类型是什么?不是文本型吗?
#10
呵,就是文本型啊,怎么没有高手来解决一下呢!
#11
为什么我的运行不成功的?总是说那个无效的字符.代码明明没有错误,想获取IP.但写入了上面getip()这个函数后,就没法运行了.老是提示第一行的出现无效字符.谁能帮帮我?感激不尽
#1
获取IP的函数
调用方法IP=getIP()就行了,Try!
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
调用方法IP=getIP()就行了,Try!
#2
引楼上方法
ip=Request.ServerVariables("Remote_HOST")//****************
更
IP=getIP()
ip=Request.ServerVariables("Remote_HOST")//****************
更
IP=getIP()
#3
好像没用啊,查看了下,IP字段内容还是空的。啥都没有。是不是我弄错了还是?调用的获取IP函数的代码放的位置有限制吗?请帮我再细说下,可以不?
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
#4
那你要保证你的if 语句为真了,它才会执行下去呀,完整的你是怎样写的呀!?
#5
<%
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
%>
<%if sendok=0 then%>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="CENTER" valign=top style="line-height:200%;font-size:12px">
<form name="form" method="post" action="<%=linkcontact%>?id=<%=id%>" onsubmit="return checkinput(form)" autocomplete = "off">
<tr>
<td width="80" align=right style="font-size:12px">标题:</td>
<td width="420">
<input type="text" name="subject" maxlength=60 size=40 class="input" value=<%=subject%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">邮箱号码:</td>
<td width="420">
<input type="text" name="from" maxlength=60 size=40 class="input" value=<%=from%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的姓名:</td>
<td width="420">
<input type="text" name="name" maxlength=60 size=20 class="input" value=<%=name%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">单位:</td>
<td width="420">
<input type="text" name="company" maxlength=60 size=40 class="input" value=<%=company%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">地址:</td>
<td width="420">
<input type="text" name="address" maxlength=60 size=40 class="input" value=<%=address%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">电话:</td>
<td width="420">
<input type="text" name="telphone" maxlength=60 size=40 class="input" value=<%=telphone%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">传真:</td>
<td width="420">
<input type="text" name="fax" maxlength=60 size=30 class="input" value=<%=fax%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的IP:</td>
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value=<%=getip()%>>
</td>
</tr>
<tr>
<td align=right style="font-size:12px">内容:</td>
<td>
<textarea rows=10 cols=50 name="body" style="font-family:宋体" class="input"><%=body%></textarea><br><font color="#00CC00">*建议填写</font>
</td>
</tr>
<tr>
<td align=center height=30 valign=middle> <br>
</td>
<td height=30 valign=middle>
<input type="image" border="0" name="imageField2" src="images/contact/bt_sendc.gif" width="40" height="18">
<img border="0" name="imageField2" src="images/contact/bt_resetc.gif" width="40" height="18" onclick="javascript:document.form.reset();document.form.subject.focus()" style="cursor:hand;">
</td>
</tr>
</form>
可以看下这些代码吗?我是这样弄的,IF语句应该是真的吧,其他的文本框中的数据都成功添加到数据库中了,只有IP字段的是空的。
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email<>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP()
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
%>
<%if sendok=0 then%>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="CENTER" valign=top style="line-height:200%;font-size:12px">
<form name="form" method="post" action="<%=linkcontact%>?id=<%=id%>" onsubmit="return checkinput(form)" autocomplete = "off">
<tr>
<td width="80" align=right style="font-size:12px">标题:</td>
<td width="420">
<input type="text" name="subject" maxlength=60 size=40 class="input" value=<%=subject%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">邮箱号码:</td>
<td width="420">
<input type="text" name="from" maxlength=60 size=40 class="input" value=<%=from%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的姓名:</td>
<td width="420">
<input type="text" name="name" maxlength=60 size=20 class="input" value=<%=name%>><font color=red>* 必填项</font>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">单位:</td>
<td width="420">
<input type="text" name="company" maxlength=60 size=40 class="input" value=<%=company%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">地址:</td>
<td width="420">
<input type="text" name="address" maxlength=60 size=40 class="input" value=<%=address%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">电话:</td>
<td width="420">
<input type="text" name="telphone" maxlength=60 size=40 class="input" value=<%=telphone%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">传真:</td>
<td width="420">
<input type="text" name="fax" maxlength=60 size=30 class="input" value=<%=fax%>>
</td>
</tr>
<tr>
<td width="80" align=right style="font-size:12px">您的IP:</td>
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value=<%=getip()%>>
</td>
</tr>
<tr>
<td align=right style="font-size:12px">内容:</td>
<td>
<textarea rows=10 cols=50 name="body" style="font-family:宋体" class="input"><%=body%></textarea><br><font color="#00CC00">*建议填写</font>
</td>
</tr>
<tr>
<td align=center height=30 valign=middle> <br>
</td>
<td height=30 valign=middle>
<input type="image" border="0" name="imageField2" src="images/contact/bt_sendc.gif" width="40" height="18">
<img border="0" name="imageField2" src="images/contact/bt_resetc.gif" width="40" height="18" onclick="javascript:document.form.reset();document.form.subject.focus()" style="cursor:hand;">
</td>
</tr>
</form>
可以看下这些代码吗?我是这样弄的,IF语句应该是真的吧,其他的文本框中的数据都成功添加到数据库中了,只有IP字段的是空的。
#6
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这一段的IP有没有显示出来呢,如果有的话(应该是有的吧)那是你其他地方的错误啦
不知道你的代码为什么没有end if,而且sendOK=0的条件下,既是写进数据库,又是显示填写表单,而表单里的action也并不是提交到本页的
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这一段的IP有没有显示出来呢,如果有的话(应该是有的吧)那是你其他地方的错误啦
不知道你的代码为什么没有end if,而且sendOK=0的条件下,既是写进数据库,又是显示填写表单,而表单里的action也并不是提交到本页的
#7
<td width="420">
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这里在点留言时,文本框中是显示出来了IP地址。但就是点提交后没写入到数据库中。end if 代码上有的,刚才贴的时候忘贴上去了,action是提交到本页的,只不过换了种链接方式。其他文本框里面的内容都是可以成功写入到数据库里面去的。但惟独这个IP写不到数据库的IP字段里面去。我两个地方写对了吗(下列我用//*******标示的)?
<%
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email <>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP() //******************************
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip //******************************
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
end if
end if
%>
<input type="text" name="ip" maxlength=60 size=30 class="input" value= <%=getip()%>>
</td>
这里在点留言时,文本框中是显示出来了IP地址。但就是点提交后没写入到数据库中。end if 代码上有的,刚才贴的时候忘贴上去了,action是提交到本页的,只不过换了种链接方式。其他文本框里面的内容都是可以成功写入到数据库里面去的。但惟独这个IP写不到数据库的IP字段里面去。我两个地方写对了吗(下列我用//*******标示的)?
<%
set rs=Server.CreateObject("ADODB.Recordset")
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
if sendok=0 then
if Request.ServerVariables("REQUEST_METHOD") = "POST" and email <>"" then
sender = Request.Form("from")
sender1=Request.Form("from1")
subject = Request.Form("subject")
content=Request.Form("body")
name = Request.Form("name")
company = Request.Form("company")
address = Request.Form("address")
telphone = Request.Form("telphone")
fax = Request.Form("fax")
ip=getIP() //******************************
content=Request.Form("body")
sqltext="select * from contact"
rs.Open sqltext,cn,1,2
rs.AddNew
rs("title")=subject
rs("email")=sender
'rs("email1")=sender1
rs("name")=name
rs("toname")=toname
rs("compa")=company
rs("add")=address
rs("tel")=telphone
rs("fax")=fax
rs("ip")=ip //******************************
rs("body")=content
rs("toid")=checkrad
rs("creatdate")=now()
rs.Update
rs.Close
end if
end if
%>
#8
对的啊,暂时没发现错误,这可就奇迹了哦
数据库里的类型是文本吧
可是如果有错误应该是会报错的呀,呵呵,神奇!
数据库里的类型是文本吧
可是如果有错误应该是会报错的呀,呵呵,神奇!
#9
是啊,晕了哦。数据库IP字段类型是文本型的。也没报什么错,其他的内容都成功写入到数据库中了,惟独这个IP没写进去。真是晕了哦。一般放IP的字段类型是什么?不是文本型吗?
#10
呵,就是文本型啊,怎么没有高手来解决一下呢!
#11
为什么我的运行不成功的?总是说那个无效的字符.代码明明没有错误,想获取IP.但写入了上面getip()这个函数后,就没法运行了.老是提示第一行的出现无效字符.谁能帮帮我?感激不尽