Time and date functions allow you to customize your web pages in many different ways. Here are some of the most commonly used time and date functions:
DateValue
strResult = DateValue("September 30, 1970")
The DateValue function converts an expression into a date subtype. In this example, it returns the value "9/30/1970".
Day
strResult = Day("9/30/1970")
The Day function extracts the day value from a date expression. In this example, it returns the value "30".
Weekday
strResult = Weekday("9/30/1970")
The Weekday function extracts the day value from a date expression. In this example, it returns the value "4".
Month
strResult = Month("9/30/1970")
The Month function extracts the day value from a date expression. In this example, it returns the value "9".
Year
strResult = Year("9/30/1970")
The Year function extracts the day value from a date expression. In this example, it returns the value "1970"
Now
strResult = Now
The Now function returns the current date and time according to the current setting of the computer or server. In this example, it returns the value " 30/11/2011 07:59:42 ".
Time
strResult = Time
The Time function returns the current time according to the current settings. In this example, it returns the value " 07:59:42 ".
Hour
strResult = Hour(Now)
The Hour function returns the current time according to the current settings. In this example, it returns the value " 7 ".
Minute
strResult = Minute(Now)
The Minute function returns the current time according to the current settings. In this example, it returns the value " 59
Second
strResult = Second(Now)
The Second function returns the current time according to the current settings. In this example, it returns the value " 42 "
http://www.aspwebpro.com/aspscripts/functions/timedate.asp
Showing posts with label ASP Scripts. Show all posts
Showing posts with label ASP Scripts. Show all posts
Wednesday, 30 November 2011
STRING FUNCTIONS
String functions are a great way to manipulate and parse the data within your strings, below are some of the most commonly used ones. For our purposes, we will use this variable as an example:
strExample = "These are examples of string functions."
InStr
<% DIM strPosition strPosition = InStr(1, strExample, "examples", 1) Response.Write strPosition %>
In this example, our script returns the value: 11 . The InStr function is a powerful tool that searches text strings and returns the position of a given text substring. In this case, we search the strPosition string for the "example" and our script returns "11", which is the starting position of the word within the string.
Left
<% DIM strLeftText strLeftText = Left(strExample, 18) Response.Write strLeftText %>
In this example, our script returns the value: " These are examples ". The Left function takes a string and returns a specified number of characters starting from the left side.
Right
<% DIM strRightText strRightText = Right(strExample, 10) Response.Write strRightText %>
In this example, our script returns the value: " functions. ". The Right function takes a string and returns a specified number of characters starting from the end of the string.
Mid
<% DIM strMidText strMidText = Mid(strExample, 11, 8) Response.Write strMidText %>
In this example, our script returns the value: " examples ". The Right function takes a string and returns a specified number of characters starting from the end of the string.
Trim, LTrim, and RTrim
<% DIM strTrimText, strLTrimText, strRTrimText strTrimText = Trim(strExample) strLTrimText = LTrim(strExample) strRTrimText = RTrim(strExample) Response.Write strTrimText Response.Write strLTrimText Response.Write strRTrimText %>
In this example, all three atrTrimText, strLTrimText, and strRTrimText return our original example: "These are examples of string functions." LTrim is used to remove blank spaces at the beginning of a string. RTrim is used to remove blank spaces at the end of a string. Trim is used to remove spaces from both the beginning and the end of a string.
LCase and UCase
<% DIM strLCaseText, strUCaseText strLCaseText = LCase(strExample) strUCaseText = UCase(strExample) Response.Write strLTrimText Response.Write strRTrimText %>
In this example, strLCaseText returns the value: " these are examples of string functions. " and strUCaseText returns the value: " THESE ARE EXAMPLES OF STRING FUNCTIONS. ". As you can tell, the LCase function returns all lower case letters and the UCase function returns all upper case letters. These functions are especially useful for inserting and updating records in your database because they help keep your data consistent.
Len
<% DIM intLenText intLenText = Len(strExample) Response.Write intLenText %>
In this example, intLenExample returns the value: " 39 " . The Len function returns the number of characters in a given string.
String
<% DIM strMyExample strMyExample = String(1, 97) Response.Write strMyExample %>
In this example, strMyExample returns the value: " a " . The String function takes a character code (97) and returns its character (a). The (1) in this case controls how many time the "a" will be displayed.
http://www.aspwebpro.com/aspscripts/functions/string.asp
strExample = "These are examples of string functions."
InStr
<% DIM strPosition strPosition = InStr(1, strExample, "examples", 1) Response.Write strPosition %>
In this example, our script returns the value: 11 . The InStr function is a powerful tool that searches text strings and returns the position of a given text substring. In this case, we search the strPosition string for the "example" and our script returns "11", which is the starting position of the word within the string.
Left
<% DIM strLeftText strLeftText = Left(strExample, 18) Response.Write strLeftText %>
In this example, our script returns the value: " These are examples ". The Left function takes a string and returns a specified number of characters starting from the left side.
Right
<% DIM strRightText strRightText = Right(strExample, 10) Response.Write strRightText %>
In this example, our script returns the value: " functions. ". The Right function takes a string and returns a specified number of characters starting from the end of the string.
Mid
<% DIM strMidText strMidText = Mid(strExample, 11, 8) Response.Write strMidText %>
In this example, our script returns the value: " examples ". The Right function takes a string and returns a specified number of characters starting from the end of the string.
Trim, LTrim, and RTrim
<% DIM strTrimText, strLTrimText, strRTrimText strTrimText = Trim(strExample) strLTrimText = LTrim(strExample) strRTrimText = RTrim(strExample) Response.Write strTrimText Response.Write strLTrimText Response.Write strRTrimText %>
In this example, all three atrTrimText, strLTrimText, and strRTrimText return our original example: "These are examples of string functions." LTrim is used to remove blank spaces at the beginning of a string. RTrim is used to remove blank spaces at the end of a string. Trim is used to remove spaces from both the beginning and the end of a string.
LCase and UCase
<% DIM strLCaseText, strUCaseText strLCaseText = LCase(strExample) strUCaseText = UCase(strExample) Response.Write strLTrimText Response.Write strRTrimText %>
In this example, strLCaseText returns the value: " these are examples of string functions. " and strUCaseText returns the value: " THESE ARE EXAMPLES OF STRING FUNCTIONS. ". As you can tell, the LCase function returns all lower case letters and the UCase function returns all upper case letters. These functions are especially useful for inserting and updating records in your database because they help keep your data consistent.
Len
<% DIM intLenText intLenText = Len(strExample) Response.Write intLenText %>
In this example, intLenExample returns the value: " 39 " . The Len function returns the number of characters in a given string.
String
<% DIM strMyExample strMyExample = String(1, 97) Response.Write strMyExample %>
In this example, strMyExample returns the value: " a " . The String function takes a character code (97) and returns its character (a). The (1) in this case controls how many time the "a" will be displayed.
http://www.aspwebpro.com/aspscripts/functions/string.asp
MATHEMATICAL FUNCTIONS
Math functions allow you to perform a variety of operations on number values in your scripts. Here are some of the most commonly used math functions:
Abs
intResult = Abs(intNumber)
The Abs function takes a number and returns its absolute value.
Exp
intResult = Exp(intNumber)
The Exp function takes a numeric value and returns e (the base of natural logarithms) raised to a power.
Hex
intResult = Hex(intNumber)
The Hex function returns a string value containing the value of an arguement converted to hexadecimal format. If the arguement is a fractional value, it is rounded to the nearest whole number before the function returns the string.
Int
intResult = Int(intNumber)
The Int function returns the whole number portion of a numeric arguement. If the arguement is a negative value, it returns the first integer value that is less than or equal to the arguement.
Fix
intResult = Fix(intNumber)
The Fix function returns the whole number portion of a numeric arguement. If the arguement is a negative value, it returns the first integer value that is greater than or equal to the arguement.
Rnd
intResult = Rnd[(switch)]
The Rnd function returns a random number. Switch indicates how the random number will be determined. If switch is a positive number, the next random number in the sequence should be returned. Before calling this function, you should initialize it by using the Randomize statement.
Sgn
intResult = Sgn(intNumber)
The Sgn function returns a numeric vale representing the sign of a number arguement. It returns 1 if the numeric value is > 0, 0 if = 0, and -1 if < 0.
Sqr
intResult = Sqr(intNumber)
The Sqr function returns the square root of a numeric arguement.
Sin
intResult = Sin(intNumber)
The Sin function returns the sine of an angle.
Tan
intResult = Tan(intNumber)
The Tan function returns the tangent of an angle.
http://www.aspwebpro.com/aspscripts/functions/math.asp
Abs
intResult = Abs(intNumber)
The Abs function takes a number and returns its absolute value.
Exp
intResult = Exp(intNumber)
The Exp function takes a numeric value and returns e (the base of natural logarithms) raised to a power.
Hex
intResult = Hex(intNumber)
The Hex function returns a string value containing the value of an arguement converted to hexadecimal format. If the arguement is a fractional value, it is rounded to the nearest whole number before the function returns the string.
Int
intResult = Int(intNumber)
The Int function returns the whole number portion of a numeric arguement. If the arguement is a negative value, it returns the first integer value that is less than or equal to the arguement.
Fix
intResult = Fix(intNumber)
The Fix function returns the whole number portion of a numeric arguement. If the arguement is a negative value, it returns the first integer value that is greater than or equal to the arguement.
Rnd
intResult = Rnd[(switch)]
The Rnd function returns a random number. Switch indicates how the random number will be determined. If switch is a positive number, the next random number in the sequence should be returned. Before calling this function, you should initialize it by using the Randomize statement.
Sgn
intResult = Sgn(intNumber)
The Sgn function returns a numeric vale representing the sign of a number arguement. It returns 1 if the numeric value is > 0, 0 if = 0, and -1 if < 0.
Sqr
intResult = Sqr(intNumber)
The Sqr function returns the square root of a numeric arguement.
Sin
intResult = Sin(intNumber)
The Sin function returns the sine of an angle.
Tan
intResult = Tan(intNumber)
The Tan function returns the tangent of an angle.
http://www.aspwebpro.com/aspscripts/functions/math.asp
CONVERSION FUNCTIONS
Conversion functions allow you to change the subtype of a variable. VBScript assigns the variant type to all variables as a default, but there are many cases when you might have to convert a variable to a particular type to satisfy an arguement. A common example would be that you might have a string arguement that returns a numeric value or a numeric arguement that returns a string value. Here are some of the most commonly used conversion functions:
CByte
CByte(strExample)
The CByte function converts this variable to a subtype byte.
CDbl
CDbl(strExample)
The CDbl function converts this variable to a subtype double.
CInt
CInt(strExample)
The CInt function converts this variable to a subtype integer.
CLng
CLng(strExample)
The CLng function converts this variable to a subtype long.
CStr
CStr(strExample)
The CStr function converts this variable to a subtype string.
http://www.aspwebpro.com/aspscripts/functions/conversion.asp
CByte
CByte(strExample)
The CByte function converts this variable to a subtype byte.
CDbl
CDbl(strExample)
The CDbl function converts this variable to a subtype double.
CInt
CInt(strExample)
The CInt function converts this variable to a subtype integer.
CLng
CLng(strExample)
The CLng function converts this variable to a subtype long.
CStr
CStr(strExample)
The CStr function converts this variable to a subtype string.
http://www.aspwebpro.com/aspscripts/functions/conversion.asp
SUGGEST USERNAME
If you have a members only website where users can register a unique username and become members, one common inconvenience for your users is that they will try to register a username that has already been registered by someone else. Well, rather than just displaying a message like "That username is already taken, please try a different username." and keep them guessing at usernames, wouldn't it be nice to suggest a similar username to them that is definitely available? Sure it would. Here is how we do it.
The first thing you need to do is create a database called MyDatabase. Then create a table called tblUsers with these fields:
ID - autonumber
fUsername - text field
fPassword - text field
fEmail - text field
fDateEntered - date/time field
Now, enter these usernames into your database: bob, bob1, bob2. The password and email fields are here just as formalities for this exercise.
Next, create a page called register.asp page with the code below
Next, create a page called confirm.asp with the code below:
<% DIM strUsername, strPassword, strEmail strUsername = Request.Form("Username") strPassword = Request.Form("Password") strEmail = Request.Form("Email") IF strUsername <> "" AND strPassword <> "" AND strEmail <> "" THEN
DIM mySQL, objRS
mySQL = "SELECT * FROM tblMembers WHERE fUsername = ' " & strUsername & " ' "
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
objRS.AddNew
objRS("fUsername")
objRS("fPassword")
objRS("fEmail")
objRS.Update
objRS.Close
Set objRS = Nothing
Response.Write "You have been successfully registered as: " & strUsername
ELSE
DIM X, strTempUsername, intCount, mySQL2, objRS2
DO UNTIL X=True
intCount = intCount + 1
strTempUsername = strUsername & intCount
strUsername = strTempUsername
mySQL2 = "SELECT * FROM tblMembers WHERE fUsername = ' " & strUsername & " ' "
Set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open mySQL2, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS2.EOF THEN
X=True
ELSE
intCount = intCount
END IF
LOOP
objRSa2.Close
Set objRSa2 = Nothing
Response.Write "That username has already been registered. Please click Back on your browser and try a different username. "
Response.Write "We suggest you try the below available username:"
Response.Write "• " & strUsername2 & ""
END IF
ELSE
Response.Write "Please click Back on your browser and complete all three fields"
END IF
%>
That's it! Now, you have a fully automated allbeit simple username suggestion tool. Try testing it. If a user tries to enter "bob", the script will suggest "bob12". If a user tries to enter "bob1", the script will suggest "bob11". Happy registering!
http://www.aspwebpro.com/aspscripts/websitetools/suggestusername.asp
The first thing you need to do is create a database called MyDatabase. Then create a table called tblUsers with these fields:
ID - autonumber
fUsername - text field
fPassword - text field
fEmail - text field
fDateEntered - date/time field
Now, enter these usernames into your database: bob, bob1, bob2. The password and email fields are here just as formalities for this exercise.
Next, create a page called register.asp page with the code below
Next, create a page called confirm.asp with the code below:
<% DIM strUsername, strPassword, strEmail strUsername = Request.Form("Username") strPassword = Request.Form("Password") strEmail = Request.Form("Email") IF strUsername <> "" AND strPassword <> "" AND strEmail <> "" THEN
DIM mySQL, objRS
mySQL = "SELECT * FROM tblMembers WHERE fUsername = ' " & strUsername & " ' "
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
objRS.AddNew
objRS("fUsername")
objRS("fPassword")
objRS("fEmail")
objRS.Update
objRS.Close
Set objRS = Nothing
Response.Write "You have been successfully registered as: " & strUsername
ELSE
DIM X, strTempUsername, intCount, mySQL2, objRS2
DO UNTIL X=True
intCount = intCount + 1
strTempUsername = strUsername & intCount
strUsername = strTempUsername
mySQL2 = "SELECT * FROM tblMembers WHERE fUsername = ' " & strUsername & " ' "
Set objRS2 = Server.CreateObject("ADODB.Recordset")
objRS2.Open mySQL2, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS2.EOF THEN
X=True
ELSE
intCount = intCount
END IF
LOOP
objRSa2.Close
Set objRSa2 = Nothing
Response.Write "That username has already been registered. Please click Back on your browser and try a different username. "
Response.Write "We suggest you try the below available username:"
Response.Write "• " & strUsername2 & ""
END IF
ELSE
Response.Write "Please click Back on your browser and complete all three fields"
END IF
%>
That's it! Now, you have a fully automated allbeit simple username suggestion tool. Try testing it. If a user tries to enter "bob", the script will suggest "bob12". If a user tries to enter "bob1", the script will suggest "bob11". Happy registering!
http://www.aspwebpro.com/aspscripts/websitetools/suggestusername.asp
SEARCH ENGINE
So when would you need a search engine on your website. Well, one popular example is an FAQ (frequently asked questions) database. You could merely list all of your FAQ's on one page, but if you have a lot of them like the Micsoft Knowledge Base, then it would be a good idea to let your users search your database by keyword or phrase.
The first thing you need to do is create a database called MyDatabase. Then create a table called tblFAQ with these fields:
ID - autonumber
Question - text field
Answer - text field
DateEntered - date/time field
Then, start adding some questions and answers to your database.
Next, create a page called searchengine.asp and copy the below code into your page:
<% DIM strSearchterm strSearchterm = Request.Form("searchterm") IF strSearchterm <> "" THEN
DIM mySQL, objRS
mySQL = "SELECT * FROM tblFAQ WHERE (Question LIKE '%" & strSearchterm & "%') OR (Answer LIKE '%" & strSearchterm & "%')"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
Response.Write "Sorry, no records were found for that searchterm"
ELSE
%>
<% ELSE ' No searchterm submitted, display blank END IF %>
This script will display your search form each time the page is accessed. When a search term is submitted, it will search both the question and answer fields in your database for any data that contains the search term. There you have it. Your first albeit simple search engine.
http://www.aspwebpro.com/aspscripts/websitetools/searchengine.asp
The first thing you need to do is create a database called MyDatabase. Then create a table called tblFAQ with these fields:
ID - autonumber
Question - text field
Answer - text field
DateEntered - date/time field
Then, start adding some questions and answers to your database.
Next, create a page called searchengine.asp and copy the below code into your page:
<% DIM strSearchterm strSearchterm = Request.Form("searchterm") IF strSearchterm <> "" THEN
DIM mySQL, objRS
mySQL = "SELECT * FROM tblFAQ WHERE (Question LIKE '%" & strSearchterm & "%') OR (Answer LIKE '%" & strSearchterm & "%')"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
Response.Write "Sorry, no records were found for that searchterm"
ELSE
%>
Question | Answer |
<%=objRS("Question")%> | <%=objRS("Answer")%> |
<% ELSE ' No searchterm submitted, display blank END IF %>
This script will display your search form each time the page is accessed. When a search term is submitted, it will search both the question and answer fields in your database for any data that contains the search term. There you have it. Your first albeit simple search engine.
http://www.aspwebpro.com/aspscripts/websitetools/searchengine.asp
FORGOT PASSWORD
One common problem with having a secure website is that occassionally members will lose or forget their login password. Well, if you collect their email address when they first register, this is an easy problem to handle. You can simply include a "Forgot Password" where the user enters the email address that they registered with and their password will be sent to them immediately.
The first thing you need to do is create a database called MyDatabase. Then create a table called tblUsers with these fields:
ID - autonumber
fUsername - text field
fPassword - text field
fEmail - text field
fDateEntered - date/time field
Now, create a page called password.asp page with the code below
Next, create a page called confirm.asp with the code below:
<% DIM strEmail strEmail = Request.Form("Email") IF strEmail <> "" THEN
%>
<% DIM mySQL, objRS mySQL = "SELECT fEmail,fPassword FROM tblMembers WHERE fEmail = '" & strEmail & "'" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn IF objRS.EOF THEN Response.Write "That email address was not found in our database. Please click Back on your browser and enter the email address you registered with." ELSE DIM strPassword strPassword = objRS("fPassword") DIM mail, objMail Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.From = "email@yourdomain.com" objMail.Subject = "Password" objMail.To = strEmail objMail.Body = "Here is your login password: " & strEmail objMail.Send Set objMail = nothing Response.Write "Your password has been sent to your email address." END IF ELSE Response.Write "Please click Back on your browser and enter the email address you registered with." END IF %>
In this example, we are using the CDONTS email component to send our email. You can easily replace this with a different email component script like ASPMail or ASPEmail. That's all there is to it. Now, you have a fully automated Forgot Password tool that your website members can use anytime without hassle. That's customer service!
The first thing you need to do is create a database called MyDatabase. Then create a table called tblUsers with these fields:
ID - autonumber
fUsername - text field
fPassword - text field
fEmail - text field
fDateEntered - date/time field
Now, create a page called password.asp page with the code below
Next, create a page called confirm.asp with the code below:
<% DIM strEmail strEmail = Request.Form("Email") IF strEmail <> "" THEN
%>
<% DIM mySQL, objRS mySQL = "SELECT fEmail,fPassword FROM tblMembers WHERE fEmail = '" & strEmail & "'" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn IF objRS.EOF THEN Response.Write "That email address was not found in our database. Please click Back on your browser and enter the email address you registered with." ELSE DIM strPassword strPassword = objRS("fPassword") DIM mail, objMail Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.From = "email@yourdomain.com" objMail.Subject = "Password" objMail.To = strEmail objMail.Body = "Here is your login password: " & strEmail objMail.Send Set objMail = nothing Response.Write "Your password has been sent to your email address." END IF ELSE Response.Write "Please click Back on your browser and enter the email address you registered with." END IF %>
In this example, we are using the CDONTS email component to send our email. You can easily replace this with a different email component script like ASPMail or ASPEmail. That's all there is to it. Now, you have a fully automated Forgot Password tool that your website members can use anytime without hassle. That's customer service!
EMAIL THIS PAGE
Another simple and very valuable tool to add to your website is the Email This Page tool. In this example, you can allow users to send the URL of any page within your website to any email address they choose. For our purposes, we will use ASPMail for sending mail
First, place this link on your home page:
ASP Web Pro
Email This Page
Next, create a page in your root directory called emailthispage.asp and paste the following code:
ASP Web Pro
Last, create a confirmation page called emailthispageconfirm.asp, paste the following code, and customize it with your own domain name and mailing info:
ASP Web Pro
<%
DIM Mailer, strEmail, strMsgHeader, qryItem, strMsgInfo
DIM strYourEmail, strYourName, strRecipEmail, strRecipName, strComments, strURL, Mail
strYourEmail = Request.Form("YourEmail")
strYourName = Request.Form("YourName")
strRecipEmail = Request.Form("RecipEmail")
strRecipName = Request.Form("RecipName")
strComments = Request.Form("Comments")
strURL = Request.Form("URL")
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromAddress = strYourEmail
Mailer.ReplyTo = strYourEmail
Mailer.RemoteHost = "YOUR_DOMAIN_NAME.COM"
Mailer.AddRecipient strRecipName, strRecipEmail
Mailer.Subject = "Look at this page from the YOUR_WEBSITE_NAME_HERE website"
strMsgHeader = "This mail message was sent from the YOUR_DOMAIN_NAME_HERE website" & vbCrLf & vbCrLf
Mailer.BodyText = strMsgHeader & vbCrLf & strRecipName & "," & vbCrLf & vbCrLf & strYourName & " wants you to take a look at this page at YOUR_WEBSITE_NAME_HERE:" & vbCrLf & "Page Link: " & strURL & vbCrLf & vbCrLf & strComments
IF Mailer.SendMail THEN
%>
<%
strYourName = request.form("YourName")
Response.Write strYourName
%>
,
ELSE
Response.Write "Sorry, there was an error and your email could not be sent at this time."
END IF
%>
That's all there is to it. The confirmation page is even customized so that it displays the sender's and recipient's names. Now, anytime one of your website users sees something interesting, they can email that page link to any email address they want. In essence, it helps drive more traffic to your website!
http://www.aspwebpro.com/aspscripts/websitetools/emailthispage.asp
First, place this link on your home page:
Email This Page
Next, create a page in your root directory called emailthispage.asp and paste the following code:
Last, create a confirmation page called emailthispageconfirm.asp, paste the following code, and customize it with your own domain name and mailing info:
<%
DIM Mailer, strEmail, strMsgHeader, qryItem, strMsgInfo
DIM strYourEmail, strYourName, strRecipEmail, strRecipName, strComments, strURL, Mail
strYourEmail = Request.Form("YourEmail")
strYourName = Request.Form("YourName")
strRecipEmail = Request.Form("RecipEmail")
strRecipName = Request.Form("RecipName")
strComments = Request.Form("Comments")
strURL = Request.Form("URL")
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromAddress = strYourEmail
Mailer.ReplyTo = strYourEmail
Mailer.RemoteHost = "YOUR_DOMAIN_NAME.COM"
Mailer.AddRecipient strRecipName, strRecipEmail
Mailer.Subject = "Look at this page from the YOUR_WEBSITE_NAME_HERE website"
strMsgHeader = "This mail message was sent from the YOUR_DOMAIN_NAME_HERE website" & vbCrLf & vbCrLf
Mailer.BodyText = strMsgHeader & vbCrLf & strRecipName & "," & vbCrLf & vbCrLf & strYourName & " wants you to take a look at this page at YOUR_WEBSITE_NAME_HERE:" & vbCrLf & "Page Link: " & strURL & vbCrLf & vbCrLf & strComments
IF Mailer.SendMail THEN
%>
<%
strYourName = request.form("YourName")
Response.Write strYourName
%>
,
Thank you for sharing this page with
<%
strRecipName = request.form("RecipName")
Response.Write strRecipName
%>
. Your message has been sent successfully and will be received by
<%
strRecipName = request.form("RecipName")
Response.Write strRecipName
%>
shortly.
ELSE
Response.Write "Sorry, there was an error and your email could not be sent at this time."
END IF
%>
That's all there is to it. The confirmation page is even customized so that it displays the sender's and recipient's names. Now, anytime one of your website users sees something interesting, they can email that page link to any email address they want. In essence, it helps drive more traffic to your website!
http://www.aspwebpro.com/aspscripts/websitetools/emailthispage.asp
Tuesday, 29 November 2011
DISPLAY RANDOM TEXT
Ever wanted to display random tips or quotes on your website? Well, Look no further. Here is a random text displayer that we used on a website we built that displays a random tip every time the browser is refreshed.
The first thing you need to do is create a database with a table called tblQuickTips with these fields:
fID - autonumber
fTip - text field or memo field depending on how long your tips are
Then, start adding some tips to your database.
Next, create a page called randomtext.asp and copy the below code into your page:
<% DIM mySQL, objRS mySQL = "SELECT MAX(fID) AS MaxTip FROM tblContent_Quick_Tips" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn Randomize DIM intRecord intRecord = Int(objRS("MaxTip") * Rnd + 1) objRS.Close Set objRS = Nothing mySQL2 = "SELECT fTip FROM tblContent_Quick_Tips WHERE fID = '" & intRecord & "'" Set objRS2 = Server.CreateObject("ADODB.Recordset") objRS2.Open mySQL2, objConn Response.Write objRS2("fText") objRS2.Close Set objRS2 = Nothing %>
All done. Just publish your page and database and click refresh on your browser. Each time you refresh, a random tip will be displayed.
http://www.aspwebpro.com/aspscripts/contentmgmt/randomtext.asp
The first thing you need to do is create a database with a table called tblQuickTips with these fields:
fID - autonumber
fTip - text field or memo field depending on how long your tips are
Then, start adding some tips to your database.
Next, create a page called randomtext.asp and copy the below code into your page:
<% DIM mySQL, objRS mySQL = "SELECT MAX(fID) AS MaxTip FROM tblContent_Quick_Tips" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn Randomize DIM intRecord intRecord = Int(objRS("MaxTip") * Rnd + 1) objRS.Close Set objRS = Nothing mySQL2 = "SELECT fTip FROM tblContent_Quick_Tips WHERE fID = '" & intRecord & "'" Set objRS2 = Server.CreateObject("ADODB.Recordset") objRS2.Open mySQL2, objConn Response.Write objRS2("fText") objRS2.Close Set objRS2 = Nothing %>
All done. Just publish your page and database and click refresh on your browser. Each time you refresh, a random tip will be displayed.
http://www.aspwebpro.com/aspscripts/contentmgmt/randomtext.asp
DISPLAY CONTENT FROM ANOTHER WEB SITE
Occasionally, it is necessary to retrieve content from another web site and display it in your own web pages. Of course, now a days most web sites that allow you to use their content on your web pages will already have their own system in place where you will just add some basic HTML to your pages and their content will display automatically so you wouldn't need this.
For those few instances, though, where you might need to do this, here is how. Assuming that you have permission to use their content, place the below script into your source code and add the URL of the page you want to retrieve the content from.
<% Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP") objHTTP.Open "GET", "http://www.domainname.com", false objHTTP.Send Response.Write objHTTP.ResponseText %>
Granted, this is a limited script so it may not suit all of your needs, but chances are if you want to do something more sophisticated than this, you probably should not be using this script. I realize this is a very touchy subject today so please use this script wisely and ALWAYS GET PERMISSION FIRST!
http://www.aspwebpro.com/aspscripts/contentmgmt/displayfromothersite.asp
For those few instances, though, where you might need to do this, here is how. Assuming that you have permission to use their content, place the below script into your source code and add the URL of the page you want to retrieve the content from.
<% Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP") objHTTP.Open "GET", "http://www.domainname.com", false objHTTP.Send Response.Write objHTTP.ResponseText %>
Granted, this is a limited script so it may not suit all of your needs, but chances are if you want to do something more sophisticated than this, you probably should not be using this script. I realize this is a very touchy subject today so please use this script wisely and ALWAYS GET PERMISSION FIRST!
http://www.aspwebpro.com/aspscripts/contentmgmt/displayfromothersite.asp
BANNER AD ROTATOR
If you want to rotate banner advertisements on your web page, you are in luck. You can use the simple and straight forward Ad Rotator component, which comes standard with ASP.
The first thing you need to do is create a text file called adrotator.txt and copy the code below:
REDIRECT /anyfile.asp
WIDTH 468
HEIGHT 60
BORDER 1
*
http://www.YOUR_DOMAIN_NAME.com/images/banner1.gif
http://www.ADVERTISER1_DOMAIN_NAME.com
Visit Advertiser1 now!
25
http://www.YOUR_DOMAIN_NAME.com/images/banner2.gif
http://www.ADVERTISER2_DOMAIN_NAME.com
Visit Advertiser2 now!
25
http://www.YOUR_DOMAIN_NAME.com/images/banner3.gif
http://www.ADVERTISER3_DOMAIN_NAME.com
Visit Advertiser3 now!
40
http://www.YOUR_DOMAIN_NAME.com/images/banner4.gif
http://www.ADVERTISER4_DOMAIN_NAME.com
Visit Advertiser4 now!
10
This schedule has four banner ads in it. The top four lines are optional, but the * is required. The Redirect send all banner ad clicks to a specified ASP file, you can use this option if you want to track banner ad statistics. The Width and Height set the dimensions of the banner ad, and the Border sets the border thickness around the banner.
After the *, you can list as manny banners as you want. Each banner that you list, consists of four lines: 1) URL of banner ad image; 2) URL users will be sent to when they click on the banner ad; 3) the image ALT text; and 4) the percentage of time that you want the banner to display on the page (must total 100 naturally).
Next, paste the following code to any ASP page where you want to display your banner ads:
<% DIM strBanners Set strBanners = Server.CreateObject("MSWC.AdRotator") Response.Write (strBanners.GetAdvertisement("/adrotator.txt")) %>
All done. Now you have a professional looking banner ad rotation system. Now, it's up to you to go out and find some advertisers!
http://www.aspwebpro.com/aspscripts/contentmgmt/banneradrotator.asp
The first thing you need to do is create a text file called adrotator.txt and copy the code below:
REDIRECT /anyfile.asp
WIDTH 468
HEIGHT 60
BORDER 1
*
http://www.YOUR_DOMAIN_NAME.com/images/banner1.gif
http://www.ADVERTISER1_DOMAIN_NAME.com
Visit Advertiser1 now!
25
http://www.YOUR_DOMAIN_NAME.com/images/banner2.gif
http://www.ADVERTISER2_DOMAIN_NAME.com
Visit Advertiser2 now!
25
http://www.YOUR_DOMAIN_NAME.com/images/banner3.gif
http://www.ADVERTISER3_DOMAIN_NAME.com
Visit Advertiser3 now!
40
http://www.YOUR_DOMAIN_NAME.com/images/banner4.gif
http://www.ADVERTISER4_DOMAIN_NAME.com
Visit Advertiser4 now!
10
This schedule has four banner ads in it. The top four lines are optional, but the * is required. The Redirect send all banner ad clicks to a specified ASP file, you can use this option if you want to track banner ad statistics. The Width and Height set the dimensions of the banner ad, and the Border sets the border thickness around the banner.
After the *, you can list as manny banners as you want. Each banner that you list, consists of four lines: 1) URL of banner ad image; 2) URL users will be sent to when they click on the banner ad; 3) the image ALT text; and 4) the percentage of time that you want the banner to display on the page (must total 100 naturally).
Next, paste the following code to any ASP page where you want to display your banner ads:
<% DIM strBanners Set strBanners = Server.CreateObject("MSWC.AdRotator") Response.Write (strBanners.GetAdvertisement("/adrotator.txt")) %>
All done. Now you have a professional looking banner ad rotation system. Now, it's up to you to go out and find some advertisers!
http://www.aspwebpro.com/aspscripts/contentmgmt/banneradrotator.asp
READ ASP COOKIES BASICS
OK, you have a script that writes an asp cookie and now you need to read the cookie each time the user returns to your website. It's really quite simple. First, we declare a few variables and then we use Request.Cookies to read the cookie from the browser and get our values.
For this example, let's say that you have a secure website that uses a username and password combination. When a user becomes a member of your site, you simply write an asp cookie to their browser that stores their username and password and any other data you want. By doing this, you can read the username and password data from the cookie each time the user returns to your site and use another ASP script to validate the cookie data with your database data. As long as the cookie data matches your database data, the user will be able to use your secure web site without any interuption.
Here is how the script looks:
<% DIM strUsername, strPassword, strFirstName, strLastName strUsername = Request.Cookies("MyCOOKIE")("Username") strPassword = Request.Cookies("MyCOOKIE")("Password") strFirstName = Request.Cookies("MyCOOKIE")("strFirstName") strLastName = Request.Cookies("MyCOOKIE")("strLastName") %>
Just replace MyCOOKIE with your own cookie name and you are on your way.
Be sure to choose a unique cookie name to use for your site. If you use a basic name like "MyCOOKIE" like in the example above, the user may visit another website that uses the same cookie name and it could write over your cookie data!
For this example, let's say that you have a secure website that uses a username and password combination. When a user becomes a member of your site, you simply write an asp cookie to their browser that stores their username and password and any other data you want. By doing this, you can read the username and password data from the cookie each time the user returns to your site and use another ASP script to validate the cookie data with your database data. As long as the cookie data matches your database data, the user will be able to use your secure web site without any interuption.
Here is how the script looks:
<% DIM strUsername, strPassword, strFirstName, strLastName strUsername = Request.Cookies("MyCOOKIE")("Username") strPassword = Request.Cookies("MyCOOKIE")("Password") strFirstName = Request.Cookies("MyCOOKIE")("strFirstName") strLastName = Request.Cookies("MyCOOKIE")("strLastName") %>
Just replace MyCOOKIE with your own cookie name and you are on your way.
Be sure to choose a unique cookie name to use for your site. If you use a basic name like "MyCOOKIE" like in the example above, the user may visit another website that uses the same cookie name and it could write over your cookie data!
WRITE ASP COOKIES BASICS
A great way of personalizing your website is through the use of asp cookies. There are a lot of things that you can do with asp cookies. This script shows you how to write basic asp cookies to the browser:
<% Response.Cookies("MyCookie")("Domain") = "www.YourDomainHere.com" Response.Cookies("MyCookie")("Expires") = Date() + 1 Response.Cookies("MyCookie")("Name") = "WebUser" %>
There you have it, now you can write asp cookies. What happens next though? After you write the cookie, you need to read it when the user returns, right? Check out Read ASP Cookies Basics to learn how.
http://www.aspwebpro.com/aspscripts/miscellaneous/writecookiebasics.asp
<% Response.Cookies("MyCookie")("Domain") = "www.YourDomainHere.com" Response.Cookies("MyCookie")("Expires") = Date() + 1 Response.Cookies("MyCookie")("Name") = "WebUser" %>
There you have it, now you can write asp cookies. What happens next though? After you write the cookie, you need to read it when the user returns, right? Check out Read ASP Cookies Basics to learn how.
http://www.aspwebpro.com/aspscripts/miscellaneous/writecookiebasics.asp
REDIRECT USER
There are a lot of cases in ASP where you would need to redirect or send a user from one page to another. One example would be if you have a membership based website. When the user logs in with his/her username and password, this information is checked by a verification script. If their login is verified, they are sent to the member page. If there username and password is incorrect, they are sent to an error page. Redirecting users is easy and only consists of one line of code:
<% Response.Redirect("/index.asp") %>
All you have to do is enter the relative path to the desired page and away your user goes!
http://www.aspwebpro.com/aspscripts/miscellaneous/redirectuser.asp
<% Response.Redirect("/index.asp") %>
All you have to do is enter the relative path to the desired page and away your user goes!
http://www.aspwebpro.com/aspscripts/miscellaneous/redirectuser.asp
PRINTER FRIENDLY PAGE
A lot of websites include valuable information that needs to be printed by the user. It could information like a news article, instructions, directions, or anything else. Sometimes you may even want your entire website to be printable. The problem is that when you print your page, the printout is not formatted correctly and all of these extra banners, menus, etc get printed as well. Well this "Printer Friendly Page" is the answer you have been looking for. There are actually a few different ways to accomplish this, here is one of them.
All you have to do is create a page called printerpage.asp and copy the code below:
Printer Friendly Page
<%
DIM view
view=request.querystring("view")
IF view <> "print" THEN
%>
<% ELSE %>
?view=view">Return to Regular View
<% END IF %>
The first time you access the page, it will display your banner and menu items. If you click the Printer Friendly Page link, the page will refresh itself with only the text you want printed.
http://www.aspwebpro.com/aspscripts/miscellaneous/printerfriendlypage.asp
All you have to do is create a page called printerpage.asp and copy the code below:
<%
DIM view
view=request.querystring("view")
IF view <> "print" THEN
%>
![]() |
My Website Menu History Products Services | Print this information. |
?view=print">Printer Friendly Page
<% ELSE %>
Print this information.
?view=view">Return to Regular View
<% END IF %>
The first time you access the page, it will display your banner and menu items. If you click the Printer Friendly Page link, the page will refresh itself with only the text you want printed.
http://www.aspwebpro.com/aspscripts/miscellaneous/printerfriendlypage.asp
SERVER VARIABLES
One way of collecting valuable web statistics is through the use of server variables. Server variables retrieve information from the user's browser. You can use these to get all kinds of useful information, such as browser details, connection methods, and more. To get a list of all of the available server variables, create a servervariables.asp page with the code below:
<% FOR EACH SV IN Request.ServerVariables Response.Write "
NEXT
%>
Next, simply publish the page and open it on the Internet. It will display a list of them for you.
http://www.aspwebpro.com/aspscripts/statistics/servervariables.asp
<% FOR EACH SV IN Request.ServerVariables Response.Write "
" & SV & " = " & request.servervariables(SV) & "
"NEXT
%>
Next, simply publish the page and open it on the Internet. It will display a list of them for you.
http://www.aspwebpro.com/aspscripts/statistics/servervariables.asp
DOWNLOAD TRACKER
Another popular web statistic that is valuable to track is how many times an item has been downloaded. This may seem a little more indepth than our other web statistic scripts, but just take it step by step and you will make it. This little script will track the title of each item that is downloaded and it will track how many times it was downloaded each day.
The first thing you need is a file to be downloaded. For our purposes, we will say that we want to download this file: http://www.aspwebpro.com/downloads/document.txt.
Second, create a web page called downloads.asp within you root directory. Then, add a hyperlink on your web page like this:
< a href="includes/downloadtracker.asp?Title=MyDocument&File=document.txt">Download My Document Here
Third, create a new table called tblDownloads in your Access database and give it these fields:
ID - Autonumber
fTitle - Text, 255
fFile - Text, 255
fDownloads - Number
fDateDownloaded - Date/Time
The fourth step is creating the downloadtracker.asp page. First, create an /includes folder within your root directory. Next, create a blank page and copy the below code into it. Lastly, save the page as downloadtracker.asp and save it within your new /includes directory.
<%
DIM mySQL, strTitle, strFile, strDate, objRS
strTitle = Request("Title")
strFile = Request("File")
strDate = Date()
mySQL = "SELECT * FROM tblDownloads WHERE fTitle = ' " & strTitle & " ' AND fDateDownloaded = ' " & strDate & " ' ;"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
objRS.AddNew
objRS("fTitle") = Request("Title")
objRS("fFile") = Request("File")
objRS("fDownloads") = 1
objRS("fDateDownloaded") = Date()
objRS.Update
ELSE
objRS.MoveFirst
DIM intCount
intCount = objRS("fDownloads")
objRS("fDownloads") = intCount + 1
objRS.Update
END IF
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Response.Redirect("/downloads/" & Request("File"))
%>
All "mySQL" statements should appear on one line in your source code to function properly.
Just create a /downloads folder within your root directory and place all of your downloads within it. Believe it or not, that's it! Now you can track which items are being downloaded from your website, how often, and how many downloads occur.
http://www.aspwebpro.com/aspscripts/statistics/downloadtracker.asp
The first thing you need is a file to be downloaded. For our purposes, we will say that we want to download this file: http://www.aspwebpro.com/downloads/document.txt.
Second, create a web page called downloads.asp within you root directory. Then, add a hyperlink on your web page like this:
< a href="includes/downloadtracker.asp?Title=MyDocument&File=document.txt">Download My Document Here
Third, create a new table called tblDownloads in your Access database and give it these fields:
ID - Autonumber
fTitle - Text, 255
fFile - Text, 255
fDownloads - Number
fDateDownloaded - Date/Time
The fourth step is creating the downloadtracker.asp page. First, create an /includes folder within your root directory. Next, create a blank page and copy the below code into it. Lastly, save the page as downloadtracker.asp and save it within your new /includes directory.
<%
DIM mySQL, strTitle, strFile, strDate, objRS
strTitle = Request("Title")
strFile = Request("File")
strDate = Date()
mySQL = "SELECT * FROM tblDownloads WHERE fTitle = ' " & strTitle & " ' AND fDateDownloaded = ' " & strDate & " ' ;"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
objRS.AddNew
objRS("fTitle") = Request("Title")
objRS("fFile") = Request("File")
objRS("fDownloads") = 1
objRS("fDateDownloaded") = Date()
objRS.Update
ELSE
objRS.MoveFirst
DIM intCount
intCount = objRS("fDownloads")
objRS("fDownloads") = intCount + 1
objRS.Update
END IF
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Response.Redirect("/downloads/" & Request("File"))
%>
All "mySQL" statements should appear on one line in your source code to function properly.
Just create a /downloads folder within your root directory and place all of your downloads within it. Believe it or not, that's it! Now you can track which items are being downloaded from your website, how often, and how many downloads occur.
http://www.aspwebpro.com/aspscripts/statistics/downloadtracker.asp
TOTAL HITS WITH TEXT FILE
On way to track the number of hits that your website receives is by using a text file counter.
The first thing to do is create a text file called totalhits.txt and save it within a directory called statistics.
Then, all you have to do is include the code below at the top of every page that you want hits counted from:
<% Set FileObject = Server.CreateObject("Scripting.FileSystemObject") HitsFile = Server.MapPath ("/statistics") & "\totalhits.txt" Set InStream= FileObject.OpenTextFile (HitsFile, 1, false ) OldHits = Trim(InStream.ReadLine) NewHits = OldHits + 1 Set OutStream= FileObject.CreateTextFile (HitsFile, True) OutStream.WriteLine(NewHits) %>
That's it. Now, you've got yourself a hit counter that uses a good old fashioned text file
http://www.aspwebpro.com/aspscripts/statistics/totalhitstxt.asp
The first thing to do is create a text file called totalhits.txt and save it within a directory called statistics.
Then, all you have to do is include the code below at the top of every page that you want hits counted from:
<% Set FileObject = Server.CreateObject("Scripting.FileSystemObject") HitsFile = Server.MapPath ("/statistics") & "\totalhits.txt" Set InStream= FileObject.OpenTextFile (HitsFile, 1, false ) OldHits = Trim(InStream.ReadLine) NewHits = OldHits + 1 Set OutStream= FileObject.CreateTextFile (HitsFile, True) OutStream.WriteLine(NewHits) %>
That's it. Now, you've got yourself a hit counter that uses a good old fashioned text file
http://www.aspwebpro.com/aspscripts/statistics/totalhitstxt.asp
TOTAL HITS WITH DATABASE
Another popular web statistic to track is the number of total hits your website receives. There are several ways to accomplish this using a global.asa file, text file, or a database. In this example, we are using an include file to record the data in an MS Access database.
The first thing you need to do is create a totalhits.asp page with the code below:
<% DIM mySQL, objRS mySQL = "SELECT * FROM tblTotalHits" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText DIM iRecordCount objRS.MoveFirst iRecordCount = objRS("Hits") objRS("Hits") = iRecordCount + 1 objRS.Update %>
Our website has received <% =objRS("Hits") %> total hits.
<% objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>
Next, we add our totalhits.asp include file to every page in our website as seen below:
Note: If you are using an HTML Editor like FrontPage or Dreamweaver, you can save time by placing your include file in your shared border or template. Then, your dailyhits.asp file will autmatically be included in every page that uses that shared border or template.
ASP Web Pro
The rest of your page here.
Now, you have a count of how many Total Hits your website has received.
http://www.aspwebpro.com/aspscripts/statistics/totalhitsdb.asp
The first thing you need to do is create a totalhits.asp page with the code below:
<% DIM mySQL, objRS mySQL = "SELECT * FROM tblTotalHits" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText DIM iRecordCount objRS.MoveFirst iRecordCount = objRS("Hits") objRS("Hits") = iRecordCount + 1 objRS.Update %>
Our website has received <% =objRS("Hits") %> total hits.
<% objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>
Next, we add our totalhits.asp include file to every page in our website as seen below:
Note: If you are using an HTML Editor like FrontPage or Dreamweaver, you can save time by placing your include file in your shared border or template. Then, your dailyhits.asp file will autmatically be included in every page that uses that shared border or template.
The rest of your page here.
Now, you have a count of how many Total Hits your website has received.
http://www.aspwebpro.com/aspscripts/statistics/totalhitsdb.asp
DAILY HITS
Another popular web statistic to track is the number of daily hits your website receives. There are several ways to accomplish this using a global.asa file, text file, or a database. In this example, we are using an include file to record the data in an MS Access database.
The first thing you need to do is create a dailyhits.asp page with the code below:
<% DIM mySQL, objRS mySQL = "SELECT * FROM tblDailyHits WHERE DateVisited = #" & Date() & "#;" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText DIM iRecordCount iRecordCount = 0 IF objRS.EOF THEN objRS.AddNew ELSE objRS.MoveFirst iRecordCount = objRS("Hits") END IF objRS("Hits") = iRecordCount + 1 objRS.Update %>
We have <% =objRS("Hits") %> hits today.
<% objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>
Next, we add our dailyhits.asp include file to every page in our website as seen below:
Note: If you are using an HTML Editor like FrontPage or Dreamweaver, you can save time by placing your include file in your shared border or template. Then, your dailyhits.asp file will autmatically be included in every page that uses that shared border or template.
ASP Web Pro
The rest of your page here.
Now, you have a count of how many Daily Hits you are receiving on your website.
http://www.aspwebpro.com/aspscripts/statistics/dailyhits.asp
The first thing you need to do is create a dailyhits.asp page with the code below:
<% DIM mySQL, objRS mySQL = "SELECT * FROM tblDailyHits WHERE DateVisited = #" & Date() & "#;" Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText DIM iRecordCount iRecordCount = 0 IF objRS.EOF THEN objRS.AddNew ELSE objRS.MoveFirst iRecordCount = objRS("Hits") END IF objRS("Hits") = iRecordCount + 1 objRS.Update %>
We have <% =objRS("Hits") %> hits today.
<% objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>
Next, we add our dailyhits.asp include file to every page in our website as seen below:
Note: If you are using an HTML Editor like FrontPage or Dreamweaver, you can save time by placing your include file in your shared border or template. Then, your dailyhits.asp file will autmatically be included in every page that uses that shared border or template.
The rest of your page here.
Now, you have a count of how many Daily Hits you are receiving on your website.
http://www.aspwebpro.com/aspscripts/statistics/dailyhits.asp
Subscribe to:
Posts (Atom)