Testa denna kod:
<%
'on error resume next
Dim objConn
Dim rstSpam, rstGB
Dim strFelmess, strSQL, strNamn, strMess, strHttp, strEmail, strIP, strPaging, strResultat
Dim dtmNow
Dim arrRows
Dim intRows, intPage, intMaxRows, intFromRow, intToRow, intPagingTo, cCount, intP
strFelmess = session("felmess")
if strFelmess <> "" then session.abandon
set objFSO = server.createObject("scripting.filesystemobject")
If request.Form("act") = "insert" then
strNamn = request.Form("namn")
strMess = request.Form("mess")
strHttp = request.Form("http")
strEmail = request.Form("email")
strSpamfilter = request.Form("spamfilter")
strIP = request.ServerVariables("REMOTE_ADDR")
strReferer = request.servervariables("http_referer")
dtmNow = now()
if strHttp = "http://" then strHttp = ""
strReferer = "default.asp?p=guestbook4"
if cStr(strNamn) = "" then strNamn = "Anonym"
if Not strSpamfilter = "10" then
session("fel") = "Wrong answer of the calculation (5+5)."
Response.redirect(strReferer)
end if
if len(cStr(strMess)) < 6 then
session("fel") = "You must write at least 5 chars."
Response.redirect(strReferer)
Else
set objFile = objFSO.opentextfile(server.mappath("guestbook4.gb"), 8, false)
objFile.write(strNamn & vbCrlf)
objFile.write(strEmail & vbCrlf)
objFile.write(strHttp & vbCrlf)
objFile.write(dtmNow & vbCrlf)
objFile.write(strMess & vbCrlf)
objFile.write("***" & vbCrlf)
objFile.close
set objFile = nothing
response.redirect(strReferer)
end if
Else
set objFile = objFSO.opentextfile(server.mappath("guestbook4.gb"), 1, false)
arrRows = split(objFile.readAll, "***")
objFile.close
set objFile = nothing
intRows = uBound(arrRows) -1
intPage = Request.querystring("gp")
intMaxRows = 10
If Len(intPage) = 0 THEN
If not (intRows / intMaxRows) mod intMaxRows then intPage = fix(intRows / intMaxRows) +1
end if
intFromRow = (intPage * intMaxRows) - intMaxRows
intToRow = intFromRow + intMaxRows -1
if intFromRow = 0 then intFromRow = 1
If intToRow > intRows then intToRow = intRows
If not (intRows / intMaxRows) mod intMaxRows then intPagingTo = fix(intRows / intMaxRows)+1
strPaging ="<b>"& intRows &"</b> messages."
If intPagingTo > 1 then
strPaging = strPaging &"<br>"
For intP = 1 to intPagingTo
if intPage = cStr(intP) then
strPaging = strPaging &" "& intP
else
strPaging = strPaging &" <a href=""default.asp?p=guestbook4&gp="& intP &""">"& intP &"</a>"& vbCrlf
end if
next
end if
For cCount = intFromRow to intToRow
arrContent = split(arrRows(cCount), vbCrlf)
cRows = uBound(arrContent)
if cRows = 5 or cRows = 6 then
if cCount mod 2 then strBgColor = "#FFFFFF" else strBgColor = "#EEF6FA"
strResultat = strResultat & vbCrlf &"<div style=""width:100%; padding:3px; padding-bottom:5px; background-color:"& strBgColor &";"">"& vbCrlf &_
vbTab &"<div class=""numberGB"">"& intRows - cCount +1&".</div>"& vbCrlf &_
vbTab &"<div class=""datePosted""><img src=""gfx_/icoClock.jpg"" alt="""& FormatDateTime(arrContent(4),2) &", "& FormatDateTime(arrContent(4),4) &""">"
if arrContent(2) <> "" then strResultat = strResultat &" <a href=""mailto:"& arrContent(2) &"""><img src=""gfx_/icoEmail.jpg"" border=""0""></a> "
if arrContent(3) <> "" then strResultat = strResultat &" <a href="""& arrContent(3) &""" target=""_blank""><img src=""gfx_/icoHttp.jpg"" border=""0""></a>"
strResultat = strResultat & "</div>"& vbCrlf & vbTab &"<div class=""fromUser"">From: "& server.HTMLEncode(Left(arrContent(1), 50)) &"</div>"& vbCrlf &_
vbTab &"<div class=""message"">"& Replace(splitWord(server.htmlEncode(arrContent(5)), 70),vbCrlf, "<br>") &"</div>"& vbCrlf &"</div>"
end if
Next
end if
set objFSO = nothing
function splitWord(strText, intLength)
arrText = split(strText, " ")
For x = 0 to uBound(arrText)
strTmpText = arrText(x)
Do until Len(strText) = 0
strTmp = strTmp & left(strTmpText,intLength) &" "
if len(strTmpText) > intLength then
strTmpText = right(strTmpText,len(strTmpText)-intLength)
else
exit do
end if
Loop
arrText(x) = strTmp
strTmp = ""
next
splitWord = Join(arrText, " ")
end function
%>
<div class="leftbar">
<% =strPaging %>
<form action="default.asp?p=guestbook4" method="post">
<input type="hidden" name="act" value="insert">
<br><br>
Your name:<br>
<input type="text" name="namn" class="gbInput"><br>
Comment (don't use enter)<br>
<textarea name="mess" cols="20" rows="10" class="gbInput"></textarea><br>
Homepage<br>
<input type="text" name="http" class="gbInput" value="http://"><br>
Email:<br>
<input type="text" name="email" class="gbInput"><br>
Vad blir 5+5?<br>
<input type="text" name="spamfilter" class="gbInput"><br>
<input type="submit" value="Insert message"> <input type="reset" value="Reset text">
</form>
</div>
<div class="rightbar">
<%= strResultat %>
</div>
Där kommer nu vara en ny ruta under mail där det står en fråga som lyder:
Vad blir 5+5? och i rutan ska dom svara 10 om dom svarar allt annat än 10 får dom ett felmeddelande där det står "Wrong answer of the calculation (5+5)"
En enkel lösning hoppas den funkar :)
