Common ASP function Set "experience is the most important" _ Application skills

Source: Internet
Author: User
Tags chr idate servervariables sql injection
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>


<%


Starttime=timer () ' Program Execution time detection





'###############################################################


' ┌──vibo───────────────────┐


' │vibo STUDIO Copyright │


' └───────────────────────┘


' Author:vibo


' Email:vibo_cn@hotmail.com


'-----------------Vibo ASP site to develop common function libraries------------------


' Opendb (vdata_url)--------------------Open the database


' GetIP ()-------------------------------Get real IP


' Getipadress (SIP)------------------------find the real address of the IP corresponding


' Ip2num (SIP)----------------------------restrict a segment of IP address


' Chkfrom ()------------------------------Anti-stop outbound submission settings


' Getsys ()-------------------------------Operating system detection


' Getbrowser ()---------------------------Browser version detection


' Getsearcher ()--------------------------Identify search engines


'


'----------------------Data filter ↓----------------------------


' Checkstr (byVal chkstr)-----------------check for invalid characters


' Checksql ()-----------------------------Prevent SQL injection





' Uncheckstr (STR)-------------------------Check for illegal SQL commands


' Checkstr (STR)--------------------------ASP Latest SQL anti-injection filtering culvert number





' HTMLEncode (restring)-------------------Filter Transform HTML code


' Datetostr (datetime,showtype)-----------Date conversion function


' Date2chinese (Idate)--------------------get ASP's Chinese date string


' Lenstr (str)----------------------------compute string Length (bytes)





' Createarr (str)-------------------------generate two-dimensional arrays


' Showrsarr (rsarr)-----------------------table structure that displays recordset GetRows generated array in a table





'----------------------an external component uses the function ↓------------------------


' SendMail (to_email,from_email,from_name,mail_subject,mail_body,mail_htmlbody)-----' JMail component Send mail





'-----------------------------------------system detection function ↓------------------------------------------


' Isvalidurl (URL)------------------------detect if a Web page is valid


' Gethtmlpage (filename)------------------get the contents of the file


' Checkfile (FilePath)--------------------Check if a file exists


' Checkdir (folderpath)-------------------Check if a directory exists


' Makenewsdir (foldername)----------------generate directory based on specified name


' Createhtmlpage (filename,filedata,c_mode) Generate files





' Checkbadword (byVal chkstr)-------------filter Dirty Word


'###############################################################





Dim Ipdata_url


Ipdata_url= "./ip.mdb"





Response.Write ("--------------Client Information detection------------" & "<br>")


Response.Write (Getsys () & "<br>")


Response.Write (Getbrowser () & "<br>")


Response.Write (Getsearcher () & "<br>")


Response.Write ("IP:" &getip () & "<br>")


Response.Write ("Source:" & (Getipadress (GetIP ()) & "<br>")


Response.Write ("<br>")





Response.Write ("--------------Data submission Detection--------------" & "<br>")


If not Chkfrom then


Response.Write ("Please do not submit content from outside the station!") "&" <br> ")


Response.End


Else


Response.Write ("Content of this site!") "&" <br><br> ")


End If








function Opendb (Vdata_url)


'------------------------------Open the database


' Use: Conn = opendb ("Data/data.mdb")


Dim Vibo_conn


Set vibo_conn= Server.CreateObject ("ADODB.") Connection ")


vibo_conn.connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (Vdata_url)


Vibo_conn.open


Opendb=vibo_conn


End Function





function GetIP ()


'-----------------------Get real IP


Userip = Request.ServerVariables ("Http_x_forwarded_for")


If Userip = "" Then Userip = Request.ServerVariables ("REMOTE_ADDR")


Getip=userip


End Function





Function getipadress (SIP)


'---------------------find the real address of the IP corresponding


Dim iparr,iprs,country,city


If sip= "127.0.0.1" then sip= "192.168.0.1"


Iparr=split (SIP, ".")


Sip=cint (Iparr (0)) *256*256*256+cint (Iparr (1)) *256*256+cint (Iparr (2)) *256+cint (Iparr (3))-1


Dim vibo_ipconn_string


vibo_ipconn_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &server.mappath (IpData_url)


Set IPRs = Server.CreateObject ("ADODB. Recordset ")


IPRs. ActiveConnection = vibo_ipconn_string


IPRs. Source = "Select top 1 city, country from address Where ip1 <=" & Sip & "and" & Sip & "<=IP2"


IPRs. CursorType = 0


IPRs. CursorLocation = 2


IPRs. LockType = 1


IPRs. Open ()





If Iprs.bof and Iprs.eof Then


country= "Unknown Area"


City= ""


Else


Country=iprs. Fields.item ("Country"). Value


City=iprs. Fields.item ("City"). Value


End If


Getipadress=country&city


IPRs. Close ()


Set IPRs = Nothing


End Function





Function ip2num (SIP)


'--------------------restrict a segment of IP address





Dim str1,str2,str3,str4


Dim num


Ip2num=0


If IsNumeric (left (sip,2)) Then


Str1=left (Sip,instr (SIP, ".") -1)


Sip=mid (Sip,instr (SIP, ".") +1)


Str2=left (Sip,instr (SIP, ".") -1)


Sip=mid (Sip,instr (SIP, ".") +1)


Str3=left (Sip,instr (SIP, ".") -1)


Str4=mid (Sip,instr (SIP, ".") +1)


Num=cint (STR1) *256*256*256+cint (str2) *256*256+cint (STR3) *256+cint (STR4)-1


Ip2num = num


End If


End Function





' Useripnum = Ip2num (Request.ServerVariables ("REMOTE_ADDR"))


' If Useripnum > Ip2num ("192.168.0.0") and Useripnum < Ip2num ("192.168.0.255") Then


' Response.Write ("<center> your IP is banned </center>")


' Response.End


' End If








Function Chkfrom ()


'----------------------------outside the station to submit settings


Dim Server_v1,server_v2, Server1, Server2


Chkfrom=false


Server1=cstr (Request.ServerVariables ("Http_referer"))


Server2=cstr (Request.ServerVariables ("SERVER_NAME"))


If Mid (Server1,8,len (server2)) =server2 Then chkfrom=true


End Function


' If not Chkfrom then


' Response.Write (please do not submit content from outside the station!) ")


' Response.End


' End If





function Getsys ()


'----------------------------------Operating system detection


Vibo_soft=request.servervariables ("Http_user_agent")


If InStr (Vibo_soft, "Windows NT 5.0") Then


Msm= "Win 2000"


ElseIf InStr (Vibo_soft, "Windows NT 5.1") Then


msm= "Win XP"


ElseIf InStr (Vibo_soft, "Windows NT 5.2") Then


Msm= "Win 2003"


ElseIf InStr (Vibo_soft, "4.0") then


msm= "Win NT"


ElseIf InStr (Vibo_soft, "NT") Then


msm= "Win NT"


ElseIf InStr (Vibo_soft, "Windows CE") Then


msm= "Windows CE"


ElseIf InStr (Vibo_soft, "Windows 9") Then


msm= "Win 9x"


ElseIf InStr (Vibo_soft, "9x") Then


msm= "Windows ME"


ElseIf InStr (Vibo_soft, "then")


Msm= "Windows 98"


ElseIf InStr (Vibo_soft, "Windows)" Then


Msm= "Windows 95"


ElseIf InStr (Vibo_soft, "Win32") Then


Msm= "Win32"


ElseIf InStr (Vibo_soft, "Unix") or InStr (Vibo_soft, "Linux") or InStr (Vibo_soft, "SunOS") or InStr (Vibo_soft, "BSD") Then


Msm= "Unix Class"


ElseIf InStr (Vibo_soft, "Mac") Then


Msm= "Mac"


Else


Msm= "Other"


End If


Getsys=msm


End Function





function Getbrowser ()


'----------------------------------browser version detection


Dim Vibo_soft


Vibo_soft=request.servervariables ("Http_user_agent")


Browser= "Unknown"


Version= "Unknown"


' Vibo_soft= ' mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Tencenttraveler. NET CLR 1.1.4322) "


If Left (vibo_soft,7) = "Mozilla" Then ' has this identity as a browser


Vibo_soft=split (Vibo_soft, ";")


If InStr (Vibo_soft (1), "MSIE") >0 Then


Browser= "Microsoft Internet Explorer"


Version=trim (Replace (Vibo_soft (1), "MSIE", ""), 6)


ElseIf InStr (Vibo_soft (4), "Netscape") >0 Then


Browser= "Netscape"


Tmpstr=split (Vibo_soft (4), "/")


Version=tmpstr (UBound (TMPSTR))


ElseIf InStr (Vibo_soft (4), "rv:") >0 Then


Browser= "Mozilla"


Tmpstr=split (Vibo_soft (4), ":")


Version=tmpstr (UBound (TMPSTR))


If InStr (version, ")") > 0 Then


Tmpstr=split (version, ")")


VERSION=TMPSTR (0)


End If


End If


ElseIf Left (vibo_soft,5) = "Opera" Then


Vibo_soft=split (Vibo_soft, "/")


Browser= "Mozilla"


Tmpstr=split (Vibo_soft (1), "")


VERSION=TMPSTR (0)


End If


If version<> "Unknown" Then


Dim TMPSTR1


Tmpstr1=trim (Replace (version, ".", ""))


If not IsNumeric (TMPSTR1) Then


Version= "Unknown"


End If


End If


Getbrowser=browser & "" & Version


End Function





function Getsearcher ()


'----------------------Identify search engines


Dim Botlist,searcher


Dim Vibo_soft


Vibo_soft=request.servervariables ("Http_user_agent")





Botlist= "Google,isaac,surveybot,baiduspider,ia_archiver,p.arthur,fast-webcrawler,java,microsoft-atl-native, Turnitinbot,webgather,sleipnir,tencenttraveler "


Botlist=split (Botlist, ",")


For i=0 to UBound (botlist)


If InStr (Vibo_soft,botlist (i)) >0 Then


Searcher=botlist (i) & "finder"


Issearch=true


Exit for


End If


Next


If Issearch Then


Getsearcher=searcher


Else


Getsearcher= "Unknown"


End If


End Function








'----------------------------------data filter ↓---------------------------------------


Function checksql () ' Prevents SQL injection


Dim Sql_injdata


Sql_injdata = "' |and|exec|insert|select|delete|update|count|*|%| Chr|mid|master|truncate|char|declare "


Sql_inj = Split (Sql_injdata, "|")


If request.querystring<> "" Then


For each sql_get in Request.QueryString


For Sql_data=0 to Ubound (Sql_inj)


If InStr (Request.QueryString (Sql_get), Sql_inj (sql_data)) >0 Then


Response.Write "<script language= ' JavaScript ' >{alert (' Do not include illegal characters in Parameters! '); History.back ( -1)}</script> "


Response.End


End If


Next


Next


End If


If request.form<> "" Then


For each sql_post in Request.Form


For Sql_data=0 to Ubound (Sql_inj)


If InStr (Request.Form (Sql_post), Sql_inj (sql_data)) >0 Then


Response.Write "<script language= ' JavaScript ' >{alert (' Do not include illegal characters in Parameters! '); History.back ( -1)} </Script> "


Response.End


End If


Next


Next


End If


End Function





Function checkstr (byVal chkstr) ' Check for invalid characters


Dim Str:str=chkstr


Str=trim (STR)


If IsNull (STR) Then


Checkstr = ""


Exit Function


End If


Dim RE


Set re=new REGEXP


Re. IgnoreCase =true


Re. Global=true


Re. Pattern= "(\ r \ n) {3,}"


Str=re. Replace (STR, "$1$1$1")


Set re=nothing


str = Replace (str, "'", "" ")


str = Replace (str, "select", "select")


str = Replace (str, "join", "join")


str = Replace (str, "union", "union")


str = Replace (str, "where", "where")


str = Replace (str, INSERT, insert)


str = Replace (str, "delete", "delete")


str = Replace (str, "Update", "Update")


str = Replace (str, "like", "like")


str = Replace (str, "Drop", "drop")


str = Replace (str, "create", "create")


str = Replace (str, "Modify", "modify")


str = Replace (str, "rename", "Rename")


str = Replace (str, "ALTER", "alter")


str = Replace (str, "cast", "cast")


Checkstr=str


End Function





Function uncheckstr (Str) ' Check for illegal SQL commands


str = Replace (str, "select", "select")


str = Replace (str, "join", "join")


str = Replace (str, "union", "union")


str = Replace (str, "where", "where")


str = Replace (str, INSERT, insert)


str = Replace (str, "delete", "delete")


str = Replace (str, "Update", "Update")


str = Replace (str, "like", "like")


str = Replace (str, "Drop", "drop")


str = Replace (str, "create", "create")


str = Replace (str, "Modify", "modify")


str = Replace (str, "rename", "Rename")


str = Replace (str, "ALTER", "alter")


str = Replace (str, "cast", "cast")


Uncheckstr=str


End Function





Function checkstr (STR) ' SQL anti-injection filtering culvert number


If Isnull (STR) Then


Checkstr = ""


Exit Function


End If


STR = Replace (STR,CHR (0), "", 1,-1, 1)


str = Replace (str, "" "," "" ", 1,-1, 1)


str = Replace (str, "<", "<", 1,-1, 1)


str = Replace (str, ">", ">", 1,-1, 1)


str = Replace (str, "script", "script", 1,-1, 0)


str = Replace (str, "script", "script", 1,-1, 0)


str = Replace (str, "script", "script", 1,-1, 0)


str = Replace (str, "script", "script", 1,-1, 1)


str = Replace (str, "Object", "Object", 1,-1, 0)


str = Replace (str, "Object", "Object", 1,-1, 0)


str = Replace (str, "Object", "Object", 1,-1, 0)


str = Replace (str, "Object", "Object", 1,-1, 1)


str = Replace (str, applet, applet, 1,-1, 0)


str = Replace (str, applet, applet, 1,-1, 0)


str = Replace (str, applet, applet, 1,-1, 0)


str = Replace (str, applet, applet, 1,-1, 1)


str = Replace (str, "[", "[")


str = Replace (str, "]", "]")


str = Replace (str, "" "", "", 1,-1, 1)


str = Replace (str, "=", "=", 1,-1, 1)


str = Replace (str, "'", "" ", 1,-1, 1)


str = Replace (str, "select", "select", 1,-1, 1)


str = Replace (str, "Execute", "execute", 1,-1, 1)


str = Replace (str, "exec", "exec", 1,-1, 1)


str = Replace (str, "join", "join", 1,-1, 1)


str = Replace (str, "union", "union", 1,-1, 1)


str = Replace (str, "where", "where", 1,-1, 1)


str = Replace (str, INSERT, INSERT, 1,-1, 1)


str = Replace (str, "delete", "delete", 1,-1, 1)


str = Replace (str, "Update", "Update", 1,-1, 1)


str = Replace (str, "like", "like", 1,-1, 1)


str = Replace (str, "Drop", "drop", 1,-1, 1)


str = Replace (str, "create", "create", 1,-1, 1)


str = Replace (str, "rename", "Rename", 1,-1, 1)


str = Replace (str, "Count", "Count", 1,-1, 1)


str = Replace (str, "CHR", "Chr", 1,-1, 1)


str = Replace (str, "Mid", "mid", 1,-1, 1)


str = Replace (str, "truncate", "truncate", 1,-1, 1)


str = Replace (str, "nchar", "nchar", 1,-1, 1)


str = Replace (str, "char", "char", 1,-1, 1)


str = Replace (str, "ALTER", "Alter", 1,-1, 1)


str = Replace (str, "cast", "cast", 1,-1, 1)


str = Replace (str, "exists", "exists", 1,-1, 1)


STR = Replace (STR,CHR), <br>, 1,-1, 1)


Checkstr = Replace (Str, "'", "" ", 1,-1, 1)


End Function





Function HTMLEncode (restring) ' Filter Transform HTML code


Dim str:str=restring


If not IsNull (STR) Then


str = UNCHECKSTR (str)


str = Replace (str, "&", "&")


str = Replace (str, ">", ">")


str = Replace (str, "<", "<")


str = Replace (str, CHR (32), "")


str = Replace (str, CHR (9), "")


str = Replace (str, CHR (9), "")


str = Replace (str, CHR (34), "" ")


str = Replace (str, CHR (39), "'")


str = Replace (str, CHR (13), "")


str = Replace (str, CHR (Ten), "<br>")


HTMLEncode = Str


End If


End Function





function Datetostr (datetime,showtype) ' Date conversion functions


Dim Datemonth,dateday,datehour,dateminute


Datemonth=month (DateTime)


Dateday=day (DateTime)


Datehour=hour (DateTime)


Dateminute=minute (DateTime)


If Len (datemonth) <2 Then datemonth= "0" &datemonth


If Len (dateday) <2 Then dateday= "0" &dateday


Select Case ShowType


Case "Y-m-d"


Datetostr=year (DateTime) & "-&DateMonth&"-"&dateday


Case "Y-m-d h:i A


Dim DATEAMPM


If datehour>12 Then


Datehour=datehour-12


Dateampm= "PM"


Else


Datehour=datehour


Dateampm= "AM"


End If


If Len (datehour) <2 Then datehour= "0" &datehour


If Len (dateminute) <2 Then dateminute= "0" &dateminute


Datetostr=year (DateTime) & "-" &DateMonth& "-" &DateDay& "" &DateHour& ":" &dateminute & "" &DATEAMPM


Case "Y-m-d h:i:s"


Dim Datesecond


Datesecond=second (DateTime)


If Len (datehour) <2 Then datehour= "0" &datehour


If Len (dateminute) <2 Then dateminute= "0" &dateminute


If Len (datesecond) <2 Then datesecond= "0" &datesecond


Datetostr=year (DateTime) & "-" &DateMonth& "-" &DateDay& "" &DateHour& ":" &dateminute & ":" &datesecond


Case "Ymdhis"


Datesecond=second (DateTime)


If Len (datehour) <2 Then datehour= "0" &datehour


If Len (dateminute) <2 Then dateminute= "0" &dateminute


If Len (datesecond) <2 Then datesecond= "0" &datesecond


Datetostr=year (DateTime) &datemonth&dateday&datehour&dateminute&datesecond


Case "YM"


Datetostr=right (Year (DateTime), 2) &datemonth


Case "D"


Datetostr=dateday


Case Else


If Len (datehour) <2 Then datehour= "0" &datehour


If Len (dateminute) <2 Then dateminute= "0" &dateminute


Datetostr=year (DateTime) & "-" &DateMonth& "-" &DateDay& "" &DateHour& ":" &dateminute


End Select


End Function





Function Date2chinese (Idate) ' Gets ASP's Chinese date string


Dim Num (10)


Dim iyear


Dim Imonth


Dim Iday





num (0) = "0"


num (1) = "One"


num (2) = "Two"


num (3) = "three"


num (4) = "Four"


num (5) = "Five"


num (6) = "Six"


num (7) = "Seven"


num (8) = "Eight"


num (9) = "Nine"





Iyear = year (Idate)


Imonth = Month (Idate)


Iday = Day (Idate)


Date2chinese = num (iyear \ 1000) + num (iyear mod) + num (iyear\) mod + num (iyear mod 10) + "year"


If Imonth >= Then


If Imonth = Ten Then


Date2chinese = Date2chinese + "Ten" + "month"


Else


Date2chinese = Date2chinese + "ten" + num (imonth Mod 10) + "Month"


End If


Else


Date2chinese = Date2chinese + num (imonth Mod 10) + "Month"


End If


If Iday >= Then


If Iday = Ten Then


Date2chinese = Date2chinese + "Ten" + "Day"


ElseIf Iday = or Iday = Then


Date2chinese = Date2chinese + num (iday \ 10) + "Ten" + "Day"


ElseIf iday > Then


Date2chinese = Date2chinese + num (iday \ 10) + "Ten" +num (Iday Mod 10) + "Day"


Else


Date2chinese = Date2chinese + "ten" + num (iday Mod 10) + "Day"


End If


Else


Date2chinese = Date2chinese + num (iday Mod 10) + "Day"


End If


End Function








Function lenstr (str) ' Compute string Length (bytes)


Dim l,t,c


Dim i


L=len (str)


T=0


For I=1 to L


C=ASC (Mid (str,i,1))


If C<0 then c=c+65536


If c<255 then t=t+1


If c>255 then t=t+2


Next


Lenstr=t


End Function





Function Createarr (str) ' generates two-dimensional array data such as: "1,a1,b1,c1,d1|2,a2,b2,c2,d2|5,a3,b3,c3,d3|8,a4,b4,c4,d4"


Dim arr ()


Str=split (str, "|")


For i=0 to UBound (str)


Arrstr=split (str (i), ",")


For j=0 to Ubound (ARRSTR)


ReDim Preserve arr (UBound (str), UBound (ARRSTR))


Arr (i,j) =arrstr (j)


Next


Next


Createarr=arr


End Function





Function Showrsarr (rsarr) ' table structure showing recordset GetRows generated array


Showhtml= "<table width=100% border=1 cellspacing=0 cellpadding=0>"


If not IsEmpty (Rsarr) Then


For y=0 to Ubound (rsarr,2)


showhtml=showhtml& "<tr>"


For x=0 to Ubound (rsarr,1)


showhtml=showhtml& "<td>" &rsarr (x,y) & "</td>"


Next


showhtml=showhtml& "</tr>"


Next


Else


rshowhtml=showhtml& "<tr>"


showhtml=showhtml& "<td>no records</td>"


showhtml=showhtml& "</tr>"


End If


showhtml=showhtml& "</table>"


Showrsarr=showhtml


End Function








'-----------------------------------------an external component uses the function ↓------------------------------------------





Function sendMail (to_email,from_email,from_name,mail_subject,mail_body,mail_htmlbody) ' JMail send mail


Set Vibo_mail = Server.CreateObject ("JMail. Message ")" To create an object to send mail


Vibo_mail.silent = True ' Mask exception error, return False to true two value J


Vibo_mail.logging = True ' Enable mail logging


Vibo_mail. Charset = "gb2312" ' Text encoding for the message is GB





' Vibo_mail. ContentType = "text/html" The format of the message is HTML format


' Vibo_mail. prority = 1 ' Mail emergency program, 1 for fastest, 5 for slowest, 3 for default value





Vibo_mail. Address of AddRecipient to_email ' mail Recipient


Vibo_mail. from = From_email ' e-mail address of sender


Vibo_mail. FromName = From_name ' sender name


Vibo_mail. Mailserverusername = "system@aaa.com" ' User name required to log on to the mail server


Vibo_mail. Mailserverpassword = "ASDASD" ' Password required to log on to the mail server


Vibo_mail. Subject = Mail_subject ' The title of the message


Vibo_mail. BODY = Mail_body ' text


Vibo_mail. HTMLBody = Mail_htmlbody ' html body


Vibo_mail. Returnreceipt = True


Vibo_mail. Send ("smtp.263xmail.com") ' Perform mail delivery (via mail server address)


Vibo_mail. Close ()


Set vibo_mail=nothing


End Function





'---------------------------------------program execution time detection ↓----------------------------------------------


Endtime=timer ()


If Endtime<starttime Then


endtime=endtime+24*3600


End If


Runtime= (endtime-starttime) *1000


Response.Write ("------------Program Execution Time detection------------" & "<br>")


Response.Write ("Program Execution Time" &runTime& "milliseconds")








'-----------------------------------------system detection using the function ↓------------------------------------------


'---------------------detect if the Web page is valid-----------------------


Function isvalidurl (URL)


Set XL = Server.CreateObject ("Microsoft.XMLHTTP")


Xl. Open "Head", Url,false


Xl. Send


Isvalidurl = (xl.status=200)


End Function


' If isvalidurl (' &fileurl& ') Then


' Response.Redirect FileURL


' Else


' Response.Write ' due to too many download users, the program detects that the file is temporarily unable to download, please replace the other download address! Thank you for your support for this software site Oh ^_^"


' End If


'------------------Check if a directory exists-------------------





Function gethtmlpage (filename) ' Get file contents


Dim Fso,file


Set FSO = Server.CreateObject ("Scripting.FileSystemObject")


Set File=fso. OpenTextFile (Server.MapPath (filename))


Showhtml=file.readall


File.close


Set file=nothing


Set fso=nothing


Gethtmlpage=showhtml ' output


End Function





Function Checkdir (FolderPath)


Dim fso


Folderpath=server.mappath (".") & "\" &folderpath


Set FSO = Server.CreateObject ("Scripting.FileSystemObject")


If FSO. FolderExists (FolderPath) Then


' Existence


Checkdir = True


Else


' does not exist


Checkdir = False


End If


Set FSO = Nothing


End Function





Function checkfile (FilePath) ' checks if a file exists


Dim FSO


Filepath=server.mappath (Filepath)


Set FSO = Server.CreateObject ("Scripting.FileSystemObject")


If FSO. FileExists (FilePath) Then


' Existence


Checkfile = True


Else


' does not exist


Checkfile = False


End If


Set FSO = Nothing


End Function





'-------------generate a directory based on the specified name---------


Function Makenewsdir (foldername)


Dim fso,f


Set FSO = Server.CreateObject ("Scripting.FileSystemObject")


Set f = fso. CreateFolder (FolderName)


Makenewsdir = True


Set FSO = Nothing


End Function





Function createhtmlpage (filename,filedata,c_mode) ' Generate file


If C_mode=0 then ' use FSO generation


Dim Fso,txt


Set fso = CreateObject ("Scripting.FileSystemObject")


Filepath=server.mappath (filename)


If checkfile (filename) then FSO. DeleteFile Filepath,true ' Prevent continued writing


Set Txt=fso. OpenTextFile (Filepath,8,true)


Txt. Write Filedata


Txt. Close


Set FSO = Nothing


ElseIf c_mode=1 Then ' use stream generation


Dim Vibostream


On Error Resume Next


Set Vibostream = Server.CreateObject ("ADODB. Stream ")





If err.number=-2147221005 Then


Response.Write "<div align= ' center ' style=" "Font-size:12px;font-family:tahoma;" > Unfortunately, your host does not support ADODB. Stream, you cannot use this program </div> "


Err.Clear


Response.End


End If





With Vibostream


. Type = 2


. Open


. CharSet = "GB2312"


. Position = Objstream.size


. WRITETEXT = Filedata


. SaveToFile Server.MapPath (filename), 2


. Close


End With


Set Vibostream = Nothing


End If


Response.Write "<div align= ' center ' style=" "Font-size:12px;font-family:tahoma;" > Congratulations! file <a href= "" "&filename&" "target=" "_blank" "style=" "Font-weight:bold;color: #FF0000;" " > "&filename&" </a> has been generated!... </div> "


Response.Flush ()


End Function





Function Checkbadword (byVal chkstr) ' Filter dirty word


Dim str:str = Chkstr


str = Trim (str)


If IsNull (STR) Then


Checkbadword = ""


Exit Function


End If





DIC = Gethtmlpage ("include/badword.txt") ' Load the Dirty word dictionary


Dicarr = Split (DIC,CHR (10))


For I =0 to Ubound (Dicarr)


Worddic = Split (Dicarr (i), "=")


STR = Replace (str,worddic (0), Worddic (1))


Next


Checkbadword = Str


End Function


%>


http://www.zzcn.net/blog/article.asp?id=69
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.