<%
from_url=Request.servervariables("http_referer")
serv_url=Request.servervariables("http_host")
if instr(from_url,serv_url)<>0 and instr(from_url,"reg.asp")<>0 then
Response.write "正確!"
else
Response.write "非法提交!"
End if
%>
你寫的
<%
if mid(From_url,8,len(Serv_url))<>Serv_url or instr(from_url,"reg.asp")=0 then
Response.Write "<script>alert('參數提交錯誤!請勿修改連結!');this.location.href='index.asp';</SCRIPT>"
Response.End
End if
%>
看紅色部分
我寫的那個判斷條件
1. instr(from_url,serv_url)<>0 判斷是否同一網域名稱,當網域名稱相同時,返回true
2. instr(from_url,"reg.asp")<>0 判斷是否從reg.asp提交過來,當是從reg.asp提交過來時,返回true
當1 和 2都成立的時候, true and true=true 提交是正確的,否則就是非法提交了
你寫的那個判斷條件
1. mid(From_url,8,len(Serv_url))<>Serv_ur 判斷是否同一網域名稱,是同一個網域名稱,返回false
2. instr(from_url,"reg.asp")=0 判斷是否從reg.asp提交過來,是從reg.asp提交過來, 返回false
當 1 成立 或 2成立時,
true or false=true
false or true=true
就是表示提交不正確
只有當1為false 而且 2為false時,才是正確提交
所以說,你寫的代碼沒有錯,邏輯上原理一樣,只是你的代碼非法提交的時候返回true,My Code是正確提交的時候返回true
而這樣寫就是非法提交的時候返回true
if not(instr(from_url,serv_url)<>0 and instr(from_url,"reg.asp")<>0) then
Response.write "非法提交!"
End if
一開始不清楚樓主是否需要在正確提交的時候也要執行代碼,所以就寫成我原來的那種,如果只需要判斷非法提交時才需要執行代碼,用你寫的代碼就OK了,用OR