Avatar billede musti776 Nybegynder
25. august 2003 - 21:34 Der er 8 kommentarer og
1 løsning

Gæstebog - sende IP sammen med beskeden!

Hej eksperter.

Jeg har en gæstebog, hvor man skriver navn, besked og sender det til et acces db, så vil jeg spørge om man ikke kan skrive et kode så man også kan sende personens IP til db sammen med det andet.

jeg vil gerne ip ban ne dem der skriver nogle ting som de ikke skulle....

Ved godt det ikke er det optimale løsning hvis de ikke har fast ip men, der er sådan set ikke andet man kan gøre, vel!?
Avatar billede ellebaek Nybegynder
25. august 2003 - 21:43 #1
IP = Request.ServerVariables("REMOTE_ADDR")

Så sætter du den bare ind i din sql. Så virker det...!
Avatar billede ellebaek Nybegynder
25. august 2003 - 21:44 #2
og mht. det at banne iper kan du..

hvis du har en tabel der indeholder de bannede iper gøre følgende:

IP = Request.ServerVariables("REMOTE_ADDR")
set rs = server.createObject("adodb.connection")
sql = "select * from bannedIP where ip = '"&IP&"'"
rs.open str
set rs = rs.execute(sql)
if rs.eof then
brugeren er ikke banned
else
brugeren er banned
end if
Avatar billede musti776 Nybegynder
25. august 2003 - 21:50 #3
jeg indsætter lige koden her ind, vil du ikke være venlig og indsætte koden så jeg bliver fri for at bruge hele natten på at prøve mig frem :)

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/Conn.asp" -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

  MM_editConnection = MM_Conn_STRING
  MM_editTable = "besked"
  MM_editRedirectUrl = "defter.asp"
  MM_fieldsStr  = "navn|value|besked|value"
  MM_columnsStr = "navn|',none,''|besked|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
set gaestebog = Server.CreateObject("ADODB.Recordset")
gaestebog.ActiveConnection = MM_Conn_STRING
gaestebog.Source = "SELECT * FROM besked ORDER BY id DESC"
gaestebog.CursorType = 0
gaestebog.CursorLocation = 2
gaestebog.LockType = 3
gaestebog.Open()
gaestebog_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
gaestebog_numRows = gaestebog_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Default</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/body.css" type="text/css">
<link rel="stylesheet" href="css/border.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="" bottommargin="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  <tr>
    <!--top banner -->
    <td width="100%" height="100" align="center" colspan="2"><img src="billeder/banner2.gif" width="790" height="100"></td>
  </tr>
  <tr align="center">
    <!--billeder -->
    <td width="0%" height="80" bgcolor="000000">&nbsp;</td>
    <td width="100%" height="80" align="left" bgcolor="000000"><img src="billeder/banner.gif" width="795" height="80"></td>
  </tr>
  <tr>
    <!-- indhold-->
    <td bgcolor="006633" align="left" valign="top" height="100%">
      <table width="118" border="0" cellspacing="0" cellpadding="2" height="160">
        <tr>
          <td width="22" height="18" align="center" valign="middle">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="default.asp">Ana sayfa</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="tarih.htm">Tarih</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="deyimler.asp">Deyimler</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="sozluk.asp">S&ouml;zl&uuml;k</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="turkuler.asp">T&uuml;rk&uuml;ler</a></td>
        </tr>
        <tr>
          <td width="22" height="9">&nbsp;</td>
          <td align="left" width="100" height="9"><a href="galleri/resimler.asp">Resimler</a></td>
        </tr>
        <tr>
          <td width="22" height="9">&nbsp;</td>
          <td align="left" width="100" height="9"><a href="defter.asp">Ziyaretci
            Defteri</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="chat/default.asp">Chat</a></td>
        </tr>
        <tr>
          <td width="22" height="9">&nbsp;</td>
          <td align="left" width="100" height="9"><a href="muzik.htm">M&uuml;zik</a></td>
        </tr>
        <tr>
          <td colspan="2" height="4">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2" height="50">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2" height="3" align="center" valign="middle"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFF00">Toplam
            ziyaretci sayisi
            <!-- #INCLUDE FILE="counter.asp" -->
            !</font></b></td>
        </tr>
      </table>
    </td>
    <td width="100%" align="center" valign="top" height="100%" bgcolor="ffffff">
      <br>
      <%
While ((Repeat1__numRows <> 0) AND (NOT gaestebog.EOF))
%>
      <table width="350" border="0" cellspacing="0" cellpadding="0" height="45">
        <tr>
          <td class="border1" height="15" align="left" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><%=(gaestebog.Fields.Item("dato").Value)%></font></td>
        </tr>
        <tr>
          <td class="border2" height="15" align="center" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><b><%=(gaestebog.Fields.Item("navn").Value)%></b></font></td>
        </tr>
        <tr>
          <td class="border2" height="15" align="left" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><%=(gaestebog.Fields.Item("besked").Value)%></font></td>
        </tr>
      </table>
      <br>
      <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  gaestebog.MoveNext()
Wend
%>
      <br>
      <form name="form1" method="POST" action="<%=MM_editAction%>">
        <table width="350" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="80"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Isim</font></td>
            <td colspan="2"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <input type="text" name="navn">
              </font></td>
          </tr>
          <tr>
            <td width="80"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Mesaj</font></td>
            <td colspan="2"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <textarea name="besked" cols="30" rows="8"></textarea>
              </font></td>
          </tr>
          <tr>
            <td width="80" height="20"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <input type="submit" name="Submit" value="G&ouml;nder">
              </font></td>
            <td height="20" width="8"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"></font></td>
            <td height="20" width="262"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <input type="reset" name="Submit2" value="Sil">
              </font></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="true">
      </form>
    </td>
  </tr>
</table>
</body>
</html>
<%
gaestebog.Close()
%>
Avatar billede ellebaek Nybegynder
25. august 2003 - 21:51 #4
har du en database du kan sende til min email ??
jens@mail.zix.dk
Avatar billede ellebaek Nybegynder
25. august 2003 - 22:01 #5
Jeg har lavet noget nu...

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/Conn.asp" -->
<%
'*** check en en bruger er banned...
set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_Conn_STRING
rs.Source = "SELECT * FROM bannedIp where ip = '" & Request.ServerVariables("REMOTE_ADDR") & "'"
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
if not rs.eof then
response.write "Du er banned"
response.end
end if


' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) <> "") Then

  MM_editConnection = MM_Conn_STRING
  MM_editTable = "besked"
  MM_editRedirectUrl = "defter.asp"
  MM_fieldsStr  = "navn|value|besked|value"
  MM_columnsStr = "navn|',none,''|besked|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End if
    MM_tableValues = MM_tableValues & MM_columns(i)
    MM_dbValues = MM_dbValues & FormVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ", Ip) values (" & MM_dbValues & ",'"&Request.ServerVariables("REMOTE_ADDR")&"')"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
set gaestebog = Server.CreateObject("ADODB.Recordset")
gaestebog.ActiveConnection = MM_Conn_STRING
gaestebog.Source = "SELECT * FROM besked ORDER BY id DESC"
gaestebog.CursorType = 0
gaestebog.CursorLocation = 2
gaestebog.LockType = 3
gaestebog.Open()
gaestebog_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
gaestebog_numRows = gaestebog_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Default</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/body.css" type="text/css">
<link rel="stylesheet" href="css/border.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="" bottommargin="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  <tr>
    <!--top banner -->
    <td width="100%" height="100" align="center" colspan="2"><img src="billeder/banner2.gif" width="790" height="100"></td>
  </tr>
  <tr align="center">
    <!--billeder -->
    <td width="0%" height="80" bgcolor="000000">&nbsp;</td>
    <td width="100%" height="80" align="left" bgcolor="000000"><img src="billeder/banner.gif" width="795" height="80"></td>
  </tr>
  <tr>
    <!-- indhold-->
    <td bgcolor="006633" align="left" valign="top" height="100%">
      <table width="118" border="0" cellspacing="0" cellpadding="2" height="160">
        <tr>
          <td width="22" height="18" align="center" valign="middle">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="default.asp">Ana sayfa</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="tarih.htm">Tarih</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="deyimler.asp">Deyimler</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="sozluk.asp">S&ouml;zl&uuml;k</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="turkuler.asp">T&uuml;rk&uuml;ler</a></td>
        </tr>
        <tr>
          <td width="22" height="9">&nbsp;</td>
          <td align="left" width="100" height="9"><a href="galleri/resimler.asp">Resimler</a></td>
        </tr>
        <tr>
          <td width="22" height="9">&nbsp;</td>
          <td align="left" width="100" height="9"><a href="defter.asp">Ziyaretci
            Defteri</a></td>
        </tr>
        <tr>
          <td width="22" height="18">&nbsp;</td>
          <td align="left" width="100" height="18"><a href="chat/default.asp">Chat</a></td>
        </tr>
        <tr>
          <td width="22" height="9">&nbsp;</td>
          <td align="left" width="100" height="9"><a href="muzik.htm">M&uuml;zik</a></td>
        </tr>
        <tr>
          <td colspan="2" height="4">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2" height="50">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="2" height="3" align="center" valign="middle"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFF00">Toplam
            ziyaretci sayisi
            <!-- #INCLUDE FILE="counter.asp" -->
            !</font></b></td>
        </tr>
      </table>
    </td>
    <td width="100%" align="center" valign="top" height="100%" bgcolor="ffffff">
      <br>
      <%
While ((Repeat1__numRows <> 0) AND (NOT gaestebog.EOF))
%>
      <table width="350" border="0" cellspacing="0" cellpadding="0" height="45">
        <tr>
          <td class="border1" height="15" align="left" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><%=(gaestebog.Fields.Item("dato").Value)%></font></td>
        </tr>
        <tr>
          <td class="border2" height="15" align="center" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><b><%=(gaestebog.Fields.Item("navn").Value)%></b></font></td>
        </tr>
        <tr>
          <td class="border2" height="15" align="left" valign="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"><%=(gaestebog.Fields.Item("besked").Value)%></font></td>
        </tr>
      </table>
      <br>
      <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  gaestebog.MoveNext()
Wend
%>
      <br>
      <form name="form1" method="POST" action="<%=MM_editAction%>">
        <table width="350" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="80"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Isim</font></td>
            <td colspan="2"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <input type="text" name="navn">
              </font></td>
          </tr>
          <tr>
            <td width="80"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Mesaj</font></td>
            <td colspan="2"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <textarea name="besked" cols="30" rows="8"></textarea>
              </font></td>
          </tr>
          <tr>
            <td width="80" height="20"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <input type="submit" name="Submit" value="G&ouml;nder">
              </font></td>
            <td height="20" width="8"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000"></font></td>
            <td height="20" width="262"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
              <input type="reset" name="Submit2" value="Sil">
              </font></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="true">
      </form>
    </td>
  </tr>
</table>
</body>
</html>
<%
gaestebog.Close()
%>

Det virker (måske).
Det kræver du har et tekstfelt ved navn: Ip i din database tabellen der indeholder gæstebogen.
Samtidig skal du have en tabel der hedder bannedIp, denne skal kun indeholde et felt: ip og et id ved autonummerering...!

Prøv det, og sig om det virker...!
Avatar billede musti776 Nybegynder
25. august 2003 - 22:42 #6
prøver den 2 sek.
Avatar billede musti776 Nybegynder
25. august 2003 - 23:40 #7
virker perfekt, takker for din hurtig svar ellebaek ....
Avatar billede ellebaek Nybegynder
25. august 2003 - 23:43 #8
anytime.
Takker for pointz..

..Ellebæk!
Avatar billede jeffe Nybegynder
25. august 2003 - 23:51 #9
Heh, du burde overveje at skære lidt ned på dine tables....og kigge lidt på CSS, så du bl.a. undgår alle de <font>
Kig evt. her www.w3schools.com
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester