制作網站的時候通常會有當訪客的一些錯誤操作或我們網站本身的缺陷,造成某個不存在的頁面被訪問,這時會出現404錯誤提示信息,如果是熱心的訪客可能會給你發一封郵件提示你,當時大部分時候是訪客不會給我們發郵件的。用ASP做一個實用的程序,當用戶訪問出現404錯誤提示信息的時候系統會自動發一封郵件給我們,這樣就不必擔心了,制作代碼如下:
以下是引用片段:
<% @language="vbscript" %>
<% Option Explicit %>
<%
Dim strPage, strReferer, strMessage
Dim obJSMTP
' Log the offending page
strPage = Request.ServerVariables("HTTP_URL")
' Log the referer
strReferer = Request.ServerVariables("HTTP_REFERER")
' Set up the email component
Set obJSMTP = Server.CreateObject("jmail.Message")
obJSMTP.From = "[email protected]"
obJSMTP.FromName = "Your Domain"
obJSMTP.Subject = "404 Error Logged"
obJSMTP.AddRecipIEnt("[email protected]")
' Write the message http://soft.knowsky.com/
strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
If strReferer <> "" Then
strMessage = strMessage & "Referer: " & strReferer
Else
strMessage = strMessage "The visitor typed the address in"
End If
obJSMTP.Body = strMessage
' Send the message
obJSMTP.Send("mail.jzxue.com")
' Tidy up
obJSMTP.ClearRecipIEnts
obJSMTP.Close()
Set obJSMTP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD Html 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<Html lang="en">
<head>
<title>404 Page Not Found</title>
<meta http-equiv="Content-Type" content="text/Html; charset=gb2312">
</head>
<body>
<h1>404 Page Not Found Error</h1>
<p>
ApPRopriate message here.
</p>
</body>
</Html>