Tips&Tricks | I trucchi del mestiere |
![]() |
Come conteggiare il numero di utenti presenti nel nostro sito |
<SCRIPT LANGUAGE="VBScript" RUNAT="Server"> Sub Application_OnStart Application("Utenti") = 0 End Sub Sub Session_OnStart ' All' ingresso di un utente, il contatore viene incrementato Session.Timeout = 5 Application.Lock Application("Utenti") = Application("Utenti") + 1 Application.UnLock End Sub Sub Session_OnEnd ' All' uscita di un utente, il contatore viene decrementato Application.Lock Application("Utenti") = Application("Utenti") - 1 Application.UnLock End Sub </SCRIPT> |
![]() |
Come inviare e-mail senza il componente CDONTS |
Dim MailSender Set MailSender = Server.CreateObject("Persits.MailSender") ' Host utilizzato MailSender.Host = "smtp.miohost.com" ' Mittente MailSender.From = "mestesso@miohost.com" ' Nome del mittente MailSender.FromName = "Pinco Pallino" ' Destinatari MailSender.AddAddress "destinatario1@host1.com" MailSender.AddAddress "destinatario2@host2.com" MailSender.AddAddress "destinatario3@host3.com" ' Oggetto MailSender.Subject = "Mail Automatica" ' Corpo del messaggio MailSender.Body = "Ciao a tutti!" ' Invio della missiva MailSender.Send() Set MailSender = Nothing |
Codice
da inserire nella pagina Web:
<%=Application("Utenti")%> |
![]() |
Come inviare un'email con ASP.NET |
dim myMail as new System.Web.Mail.MailMessage() myMail.Subject = "Mail di prova." myMail.body = "Questa Φ una mail di test." myMail.To = "paperino myMail.From = "puto@topolinia.it" smtpMail.SmtpServer = "[Nome o indirizzo IP del SMTP Server]" smtpMail.send(myMail) |
![]() |
Come reperire informazioni su un file Macromedia Flash |
<!--#include file="swfheaderdump.inc" --> <% ' Indicare il file SWF nella querystring in dato modo: ' ' swfdump.asp?swf=prova.swf set myObj = new swfdump myObj.SWFDump (Server.MapPath(request("swf"))) Response.Write "Heigt (pixel) = " & myObj.Heigt & " |
Class SWFDump Private header Private RECTdata Private nBits Private mversion Private mfilelen Private mxMin Private mxMax Private myMin Private myMax Private mheigt Private mwidth Private mframerate Private mframecount Private Sub Class_Initialize() End Sub Private Sub Class_Terminate() End Sub Private Function ReadHeader (filename) Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(filename, ForReading) ReadHeader = f.Read(21) End Function Private Function ToBin(inNumber, OutLenStr ) Dim binary binary = "" do while inNumber >= 1 binary = binary & inNumber mod 2 inNumber = inNumber \ 2 loop binary = binary & String(OutLenStr - len(binary), "0") ToBin = StrReverse(binary) End Function Private Function Bin2Decimal(inBin) Dim counter Dim temp Dim Value inBin = StrReverse(inBin) temp = 0 For counter = 1 to Len(inBin) If counter = 1 then Value = 1 Else Value = Value * 2 End If temp = temp + mid(inBin, counter ,1) * Value Next Bin2Decimal = temp End Function Public Function SWFDump(fileName) header = ReadHeader (fileName) mversion = asc(mid(header,4,1)) mfilelen = asc(mid(header,5,1)) mfilelen = mfilelen + asc(mid(header,6,1)) * 256 mfilelen = mfilelen + asc(mid(header,7,1)) * 256 * 256 mfilelen = mfilelen + asc(mid(header,8,1)) * 256 * 256 * 256 RECTdata = ToBin(asc(mid(header,9,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,10,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,11,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,12,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,13,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,14,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,15,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,16,1)),8) RECTdata = RECTdata & ToBin(asc(mid(header,17,1)),8) nBits = Mid(RECTdata,1,5) nBits = Bin2Decimal(nBits) mxMin = Bin2Decimal(Mid(RECTdata,6,nBits)) mxMax = Bin2Decimal(Mid(RECTdata,6 + nBits * 1 ,nBits)) myMin = Bin2Decimal(Mid(RECTdata,6 + nBits * 2 ,nBits)) myMax = Bin2Decimal(Mid(RECTdata,6 + nBits * 3 ,nBits)) mheigt = (myMax - myMin) / 20 mwidth = (mxMax - mxMin) / 20 mframerate = asc(mid(header,18,1)) mframecount = asc(mid(header,19,1)) mframecount = mframecount + asc(mid(header,20,1)) * 256 End Function Public Property Get Heigt() Heigt = mheigt End Property Public Property Get Width() Width = mwidth End Property Public Property Get Version() Version = mversion End Property Public Property Get FileLen() FileLen = mfilelen End Property Public Property Get xMin() xMin = mxMin End Property Public Property Get xMax() xMax = mxMax End Property Public Property Get yMin() yMin = myMin End Property Public Property Get yMax() yMax = myMax End Property Public Property Get Framerate() Framerate = mframerate End Property Public Property Get Framecount() Framecount = mframecount End Property End Class %> |
![]() |
Come importare il contenuto di un file di testo in array |
<% Const ForReading = 1 Dim myArr(4) myArr(0)="10" myArr(1)="12" myArr(2)="15" myArr(3)="17" i = 0 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile("C:\inetpub\wwwroot\prova.txt") Set objTextFile = objFile.OpenAsTextStream(ForReading) Do While objTextFile.AtEndOfStream <> True CurrLine = objTextFile.Line If Cstr(CurrLine) = Cstr(myArr(i)) Then myArr(i)=UCASE(objTextFile.ReadLine) i = i + 1 Else CurrLine = objTextFile.ReadLine End If Loop Line10 = myArr(0) Line12 = myArr(1) Line15 = myArr(2) Line17 = myArr(3) objTextFile.Close Set objFSO = Nothing Set objFile = Nothing Response.Write "Line 10 reads: " & Line10 Response.Write "Line 12 reads: " & Line12 Response.Write "Line 15 reads: " & Line15 Response.Write "Line 17 reads: " & Line17 %> |
![]() |
Come disabilitare il tasto "Indietro" di Internet Explorer |
<% Response.Expires = -1 Response.ExpiresAbsolute = Now() - 1 Response.AddHeader "pragma", "no-cache" Response.AddHeader "cache-control", "private" Response.CacheControl = "no-cache" dim qString: qString = Session("qString") & "&back=y" dim strHead: strHead = "<html><head></head><body>" dim strFoot: strFoot = "</body></html>" if Session("submitted") = "yes" then response.write strHead response.write "<script language=""JavaScript"">" response.write "location.replace(""page2.asp?" & qString & """);" response.write "</script>" response.write strFoot response.end end if response.write strHead response.write "<form action=""page2.asp"" method=""get"">" response.write "Digita qualcosa:<br>" response.write " <input type=""provatext""> <br>" response.write "<input type=""submit"">" response.write strFoot %> |
Struttura della pagina page2.asp
<% dim strHead: strHead = "<html><head></head><body>" dim strFoot: strFoot = "</body></html>" dim BackCheck: BackCheck = request("back") dim strSomething: strSomething = request("prova") Session("qString") = request.QueryString Session("submitted") = "yes" response.write strHead if BackCheck = "y" then response.write "Attenzione! Non puoi utilizzare questa funzione!<br><br>" end if response.write "you wrote: " & strSomething response.write strFoot %> |