Solved

Please check my code.

Posted on 2004-09-23
38
441 Views
Last Modified: 2006-11-17
Here is the code for my website. I'm concerned about the usual things including speed, security, etc expecially since it my first big website and I don't want to get it wrong. So any suggestions, tips, improvments etc would be really helpfull.

The database connection Access atm but will be SQL shortly when we get our server ready.

Points will be split for each piece of advise that I end up using.

Thanks in advance!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<%Set session("MyConn") = Server.CreateObject("ADODB.Connection")
DSNtemp="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("includes/menu.mdb") & ";Mode=Share Deny None;User Id=;PASSWORD=;"
session("MyConn").ConnectionTimeout = 15
session("MyConn").CommandTimeout =  10
session("MyConn").Mode = 1 'adModeRead
session("MyConn").Errors.Clear
Err.Clear
if session("MyConn").state = 0 then
session("MyConn").Open DSNtemp
end if

Set menu_count = session("MyConn").Execute("SELECT COUNT(lvid) AS menu_count FROM menu where lvid='" & request.querystring("id") & "'")
if request.querystring("id") = "" or menu_count("menu_count") = 0 then
Set menu = session("MyConn").Execute("SELECT * FROM menu where lvid='main_page'")
else
Set menu = session("MyConn").Execute("SELECT * FROM menu where lvid='" & request.querystring("id") & "'")
end if

Set setup = session("MyConn").Execute("SELECT * FROM setup")
website_title = setup("website_title")
website_address = setup("website_address")
session("media_folder") = setup("media_folder")
session("graphics_folder") = setup("graphics_folder")
session("include_folder") = setup("include_folder")
session("colourbg1") = setup("colourbg1")
session("colourbg2") = setup("colourbg2")
session("colourbg3") = setup("colourbg3")
session("colourbd1") = setup("colourbd1")
session("colourbd2") = setup("colourbd2")
session("colourbd3") = setup("colourbd3")
session("colourbd4") = setup("colourbd4")
session("coloursb1") = setup("coloursb1")
session("coloursb2") = setup("coloursb2")
session("coloursb3") = setup("coloursb3")
session("coloursearch") = setup("coloursearch")
session("news1") = setup("news1")
session("news2") = setup("news2")
session("news3") = setup("news3")

response.write "<title>" & website_title & " / " & menu("lvname") & "</title>" & vbNewLine & _
"<link href=""" & session("include_folder") & "/main.css"" rel=""stylesheet"" type=""text/css"">" & vbNewLine & _
"<link rel=""STYLESHEET"" type=""text/css"" href=""" & session("include_folder") & "/dhtmlcentral.css"">" & vbNewLine & _
"<script language=""JavaScript1.2"" src=""" & session("include_folder") & "/coolmenus4.js"">" & vbNewLine & _
"/*****************************************************************************" & vbNewLine & _
"Copyright (c) 2001 Thomas Brattli (webmaster@dhtmlcentral.com)" & vbNewLine & _
"DHTML coolMenus - Get it at coolmenus.dhtmlcentral.com Version 4.0_beta" & vbNewLine & _
"This script can be used freely as long as all copyright messages are intact." & vbNewLine & _
"******************************************************************************/" & vbNewLine & _
"</script>" & vbNewLine

Sub parseASP(ASPCode)
dim y, x
dim lasterror
y = -1
x = Instr(1, ASPCode, "<%")
Do Until x = 0
if x <> 1 then Response.Write(Mid(ASPCode, (y + 2), x - (y + 2)))
y = InStr(x + 2, ASPCode, CHR(37) & ">")
if y = 0 then response.write("Error: Unterminated delimiter found."):Response.End
On Error Resume Next
Execute(Mid(ASPCode, x + 2, y - x - 2))
lasterror = err.number
if lasterror <> 0 then
    Response.Write("<font color='red'>VBScript Runtime error:</font> " & lasterror & "<br>" & err.Description & "<br>Source: " & err.Source & "<br>")
end if
On Error Goto 0
x = Instr(x + 2, ASPCode, "<" & CHR(37))
Loop
Response.Write(Mid(ASPCode, y + 2))
End Sub

response.write "</head><body bgcolor=""" & session("colourbg1") & """ leftmargin=""0"" topmargin=""0"" rightmargin=""0"" marginwidth=""0"" marginheight=""0"" bottommargin=0 onLoad=""window.focus()"">" & vbNewLine%>

<script language="javascript">
<!--
window.defaultStatus=" My Name ";
//-->
</script>
<script language="JavaScript1.2">
<!--
oM=new makeCM("oM"); oM.resizeCheck=1; oM.rows=1;  oM.onlineRoot=""; oM.pxBetween =0;
oM.fillImg="includes/cm_fill.gif"; oM.fromTop=136; oM.fromLeft=155; oM.wait=300; oM.zIndex=400;
oM.useBar=1; oM.barWidth="100%"; oM.barHeight="menu"; oM.barX=0;oM.barY="menu"; oM.barClass="clBar";
oM.barBorderX=0; oM.barBorderY=0;
oM.level[0]=new cm_makeLevel(90,21,"clT","clTover",0,0,"clB",0,"bottom",0,0,0,0,0);
oM.level[1]=new cm_makeLevel(102,18,"clS","clSover",0,0,"clB",0,"right",0,0,"includes/menu_arrow.gif",7,9);
oM.level[2]=new cm_makeLevel(110,18,"clS2","clS2over");
oM.level[3]=new cm_makeLevel(140,18);

<%
Function ShowRecursive(joinId)
For j = 0 To UBound(arrHolder)
If arrHolder(j, 1) = joinId Then
if joinId = "index" then
response.write "oM.makeMenu('" & arrHolder(j, 0) & "','','" & arrHolder(j, 2) & "','index.asp?id=" & arrHolder(j, 0) & "');"
elseif joinId = "forms_online" then
response.write "oM.makeMenu('" & arrHolder(j, 0) & "','" & arrHolder(j, 1) & "','" & arrHolder(j, 2) & "','index.asp?id=" & arrHolder(j, 0) & "','',142,0);"
else
 response.write "oM.makeMenu('" & arrHolder(j, 0) & "','" & arrHolder(j, 1) & "','" & arrHolder(j, 2) & "','index.asp?id=" & arrHolder(j, 0) & "','',120,0);"
end if
ShowRecursive arrHolder(j, 0)
End If
Next
End Function

Set rs = Server.CreateObject("ADODB.Recordset")
Dim rs, navsql, i, arrHolder()
navsql = "SELECT lvid, menujoin, menuname FROM menu WHERE menujoin <> 'footer' AND menujoin <> 'main' AND menujoin <> 'other' AND active = 'y' ORDER BY menuorder"
rs.Open navsql, session("MyConn"), 3, 3
redim arrHolder(rs.RecordCount - 1, 2)
i = 0

While Not rs.eof
arrHolder(i, 0) = rs("lvid")
arrHolder(i, 1) = rs("menujoin")
arrHolder(i, 2) = rs("menuname")
i = i + 1
rs.MoveNext
Wend

rs.Close
set rs = nothing

Call ShowRecursive("index")
%>

oM.menuPlacement=new Array(46,135,229,315,412,508)
oM.construct()
//-->
</script>

<%response.write "<table cellpadding=0 cellspacing=0 border=0 width=""100%"" height=""100%"">" & vbNewLine & _
"<tr><td height=8></td></tr>" & vbNewLine & _
"<tr><td align=""left"" valign=""top"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=774 height=""100%"">" & vbNewLine & _
"<tr><td width=774 colspan=3 background=""" & session("graphics_folder") & "/gccbanner.jpg"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 height=158>" & vbNewLine & _
"<tr height=129><td colspan=14></td></tr>" & vbNewLine & _
"<tr height=18><td width=16></td>" & vbNewLine

if request.querystring("id") = "main_page" or request.querystring("id") = "" then response.write "<td width=18><a href=""index.asp?id=main_page"" onmouseover=""self.status='Main Page'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/homeonmain.gif"" border=0 width=18 height=18></a></td>" else response.write "<td width=18><a href=""index.asp?id=main_page"" onmouseover=""self.status='Main Page'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/homeoffmain.gif"" border=0 width=18 height=18 name=""main""></a></td>" end if
response.write "<td width=6></td>"
if request.querystring("id") = "your_council" then response.write "<td width=84><a href=""index.asp?id=your_council"" onmouseover=""self.status='Your Council'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84onmain.gif"" border=0 width=84 height=18></a></td>" else response.write "<td width=84><a href=""index.asp?id=your_council"" onmouseover=""self.status='Your Council'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84offmain.gif"" border=0 width=84 height=18 name=""84"" name=""a84""></a></td>" end if
response.write "<td width=6></td>"
if request.querystring("id") = "for_residents" then response.write "<td width=84><a href=""index.asp?id=for_residents"" onmouseover=""self.status='For Residents'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84onmain.gif"" border=0 width=84 height=18></a></td>" else response.write "<td width=84><a href=""index.asp?id=for_residents"" onmouseover=""self.status='For Residents'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84offmain.gif"" border=0 width=84 height=18 name=""a84""></a></td>" end if
response.write "<td width=6></td>"
if request.querystring("id") = "for_visitors" then response.write "<td width=84><a href=""index.asp?id=for_visitors"" onmouseover=""self.status='For Visitors'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84onmain.gif"" border=0 width=84 height=18></a></td>" else response.write "<td width=84><a href=""index.asp?id=for_visitors"" onmouseover=""self.status='For Visitors'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84offmain.gif"" border=0 width=84 height=18 name=""a84""></a></td>" end if
response.write "<td width=6></td>"
if request.querystring("id") = "news_and_events" then response.write "<td width=90><a href=""index.asp?id=news_and_events"" onmouseover=""self.status='News & Events'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/90onmain.gif"" border=0 width=90 height=18></a></td>" else response.write "<td width=90><a href=""index.asp?id=news_and_events"" onmouseover=""self.status='News & Events'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/90offmain.gif"" border=0 width=90 height=18 name=""a90""></a></td>" end if
response.write "<td width=6></td>"
if request.querystring("id") = "forms_online" then response.write "<td width=84><a href=""index.asp?id=forms_online"" onmouseover=""self.status='Forms Online'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84onmain.gif"" border=0 width=84 height=18></a></td>" else response.write "<td width=84><a href=""index.asp?id=forms_online"" onmouseover=""self.status='Forms Online'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84offmain.gif"" border=0 width=84 height=18 name=""a84""></a></td>" end if
response.write "<td width=6></td>"
if request.querystring("id") = "contact_us" then response.write "<td width=84><a href=""index.asp?id=contact_us"" onmouseover=""self.status='Contact Us'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84onmain.gif"" border=0 width=84 height=18></a></td>" else response.write "<td width=84><a href=""index.asp?id=contact_us"" onmouseover=""self.status='Contact Us'; return true"" onmouseout=""self.status=' '; return true""><img src=""" & session("graphics_folder") & "/84offmain.gif"" border=0 width=84 height=18 name=""a84""></a></td>" end if

response.write "</tr><tr height=11><td colspan=14></td></tr></table>" & vbNewLine & _
"</td></tr><tr><td width=12 height=""100%""></td><td width=572>" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=572 height=""100%"" bgcolor=""" & session("colourbg2") & """>" & vbNewLine & _
"<tr><td width=1 bgcolor=""" & session("colourbd1") & """></td><td width=571 valign=""top"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=571 height=""100%"">" & vbNewLine & _
"<tr><td colspan=3 height=8></td></tr><tr><td width=8></td><td width=555 valign=""top"">" & vbNewLine

if menu("content") <> "" or request.querystring("preview") = "y" then
if menu("active") = "y" or request.querystring("preview") = "y" then
codenewsandevents = vbNewLine & "<%if menu(""news_active"") = ""y"" or menu(""events_active"") = ""y"" then" & vbNewLine & _
"Server.Execute(""news/newsandevents.inc"")" & vbNewLine & _
"end if" & "%" & ">" & vbNewLine

codecontentbox1top = vbNewLine & "<table cellpadding=10 cellspacing=0 border=0 width=""100%"" bgcolor=""<%response.write session(""coloursb1"")" & "%" & ">" & """>" & vbNewLine & _
"<tr><td valign=""top"" class=""bodytextwhite"">" & vbNewLine

codecontentbox1base = vbNewLine & "</td></tr>" & vbNewLine & _
"<tr><td align=""right""><a href=""#top"" class=""quicklinks"" onmouseover=""self.status='Return to Top of Page'; return true"" onmouseout=""self.status=' '; return true"">top</a><img src=""<%response.write session(""graphics_folder"")" & "%" & ">" & "/arrow3.gif"" width=10 height=8></td></tr>" & vbNewLine & _
"</table>" & vbNewLine

codetemplate1top = vbNewLine & "<table cellpadding=0 cellspacing=0 border=0 width=""100%"">" & vbNewLine & _
"<tr><td height=10></td></tr><tr><td valign=""top"" align=""center"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=540>" & vbNewLine & _
"<tr><td class=""bodytextwhite"" colspan=3>" & vbNewLine & _
"<table cellpadding=5 cellspacing=0 border=0 width=""100%"" bgcolor=""<%response.write session(""coloursb1"")" & "%" & ">" & """>" & vbNewLine & _
"<tr><td class=""bodyheadingwhite"" valign=""top""><a name=""top""></a><%response.write menu(""lvname"")" & "%" & ">" & "</td></tr>" & vbNewLine & _
"</table>" & vbNewLine & _
"</td></tr>" & vbNewLine & _
"<tr><td class=""bodytextwhite"" colspan=3 height=20></td></tr><tr><td class=""bodytextwhite"">" & vbNewLine

codetemplate1base = vbNewLine & "</td></tr></table>" & vbNewLine & _
"</td></tr><tr><td height=10></td></tr></table>" & vbNewLine

codeline = vbNewLine & "<table cellpadding=0 cellspacing=5 border=0 width=""100%""><tr><td height=1 background=""" & session("graphics_folder") & "/line.gif""></td></tr></table>"

content = menu("content")
call ParseASP(content)

else
response.write "<table cellpadding=0 cellspacing=0 border=0 width=540>" & vbNewLine & _
"<tr><td class=""bodytextwhite"" align=""center""><br><br><b>Sorry!<br><br>This page is currently unavailable due to maintainance.</b></td></tr>" & vbNewLine & _
"</table>"
end if
else
response.write "<table cellpadding=0 cellspacing=0 border=0 width=540>" & vbNewLine & _
"<tr><td class=""bodytextwhite"" align=""center""><br><br><b>Error!<br><br>Page not found.<br><br>Report errors to <a href=""mailto:webmaster@gcc.qld.gov.au?subject=Page Not Found: " & menu("lvid") & "&body=Please send as is."">webmaster@gcc.qld.gov.au</a></b></td></tr>" & vbNewLine & _
"</table>"
end if
response.write "</td><td width=8></td></tr>" & vbNewLine & _
"<tr><td colspan=3 height=11 background=""" & session("graphics_folder") & "/tile1main.gif"" align=""right"" valign=""middle"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0>" & vbNewLine & _
"<tr><td bgcolor=""" & session("colourbg2") & """ class=""basenavb"" align=""center"">&nbsp;&nbsp;" & vbNewLine

Set footer = session("MyConn").Execute("SELECT lvid, lvname, active FROM menu WHERE active='y' and menujoin='footer' ORDER BY menuorder")
Set footera = session("MyConn").Execute("SELECT count(active) AS fcount FROM menu WHERE active='y' and menujoin='footer'")
footerb = 0
while not footer.eof
footerb = footerb + 1
response.write "<a href=""index.asp?id=" & footer("lvid") & """ onmouseover=""self.status='" & footer("lvname") & "'; return true"" onmouseout=""self.status=' '; return true"" class=""basenav"">" & footer("lvname") & "</a>"
if footerb < footera("fcount") then response.write " | " end if
footer.movenext
wend
footer.movefirst

response.write "&nbsp;&nbsp;" & vbNewLine & _
"</td><td width=8></td></tr></table>" & vbNewLine & _
"</td></tr><tr><td colspan=3 height=8></td></tr></table>" & vbNewLine & _
"</td></tr></table></td><td width=190>" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=190 height=""100%"" bgcolor=""" & session("colourbg3") & """>" & vbNewLine & _
"<tr><td colspan=6 height=10><img src="""  & session("graphics_folder") & "/midmain2.gif"" border=0 width=190 height=10></td></tr>" & vbNewLine & _
"<tr><td width=1 bgcolor=""" & session("colourbd2") & """></td>" & vbNewLine & _
"<td width=1></td><td width=1 bgcolor=""" & session("colourbd3") & """></td><td width=185 valign=""top"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=185 height=""100%"">" & vbNewLine & _
"<tr><td colspan=3 height=8></td></tr>" & vbNewLine & _
"<tr><td width=8></td><td width=169 valign=""top"">" & vbNewLine

Set features = session("MyConn").Execute("SELECT include FROM features where active = 'y' order by show_order asc")
while not features.eof
Server.Execute(session("include_folder") & "/" & features("include"))
response.write "<br>"
features.movenext
wend
features.movefirst

response.write "</td><td width=8></td></tr>" & vbNewLine & _
"<tr><td colspan=3 height=11 background=""" & session("graphics_folder") & "/tile2main.gif""></td></tr>" & vbNewLine & _
"<tr><td colspan=3 height=8></td></tr></table>" & vbNewLine & _
"</td><td width=1 bgcolor=""" & session("colourbd4") & """></td><td width=1 bgcolor=""" & session("colourbd1") & """></td>" & vbNewLine & _
"</tr></table>" & vbNewLine & _
"</td></tr><tr><td width=8></td><td width=762 colspan=2><img src=""" & session("graphics_folder") & "/footermain.gif"" border=0 width=762 height=2></td></tr>" & vbNewLine & _
"</table>" & vbNewLine & _
"</td></tr><tr><td height=8></td></tr></table>" & vbNewLine & _
"</body>" & vbNewLine

session("MyConn").close
set session("MyConn") = nothing
Session.Abandon

response.write "</html>" & vbNewLine & _
"<form method=""post"" name=""g"" action=""index.asp?lv1id=search&lv1name=Search"">" & vbNewLine & _
"<input type=""text"" name=""searchstring"" align=""middle"" style=""width:100px; padding:2px; border:1px solid " & session("coloursearch") & "; position:absolute; z-index:500; left:599; top:138;"" />&nbsp;" & vbNewLine & _
"<input type=""Image"" value=""Search"" name=""SubmitButton"" src=""" & session("graphics_folder") & "/searchoff.gif"" align=""middle"" style=""position:absolute; z-index:510; left:705; top:137;"" />" & vbNewLine & _
"</form>" & vbNewLine
%>

******************************************************************************
This is code for the Calendar that is a part of Features and is a Include file.

<%yr = year(date)
mth = month(date)
dy = day(date)
if dy < 10 then dy = "0" & dy end if
if mth < 10 then mth = "0" & mth end if
LastOfMonth = Day(DateSerial(yr, mth+1, 0))
firstmonth = mth & "/01/" & yr
lastmonth = DateSerial(yr, mth+1, 0)
events_query = "SELECT distinct event_date FROM eventsdates where #" & firstmonth & "# <= event_date and #" & lastmonth & "# >= event_date order by event_date asc"
Set events = session("MyConn").Execute(events_query)

response.write "<table cellpadding=0 cellspacing=0 border=0 width=169 bgcolor=""" & session("coloursb1") & """>" & vbNewLine & _
"<tr><td height=1 bgcolor=""" & session("coloursb2") & """></td></tr>" & vbNewLine & _
"<tr><td height=21 bgcolor=""" & session("coloursb3") & """ align=""center"" valign=""middle"" class=""caltitle"">Events Calendar</td></tr>" & vbNewLine & _
"<tr><td height=1 bgcolor=""" & session("coloursb2") & """></td></tr>" & vbNewLine & _
"<tr><td height=1></td></tr>" & vbNewLine

firstdy = weekdayname(weekday(mth&"/01/"&yr))
if firstdy = "Sunday" then
calmark = 0
elseif firstdy = "Monday" then
calmark = 1
elseif firstdy = "Tuesday" then
calmark = 2
elseif firstdy = "Wednesday" then
calmark = 3
elseif firstdy = "Thursday" then
calmark = 4
elseif firstdy = "Friday" then
calmark = 5
elseif firstdy = "Saturday" then
calmark = 6
end if

response.write "<tr><td align=""center"" valign=""middle"" class=""caltext"">" & monthname(mth) & "&nbsp;" & yr & "</td></tr>" & vbNewLine & _
"<tr><td height=124 align=""center"" valign=""middle"">" & vbNewLine & _
"<table cellpadding=0 cellspacing=0 border=0 width=120><tr>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">s</td>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">m</td>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">t</td>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">w</td>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">t</td>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">f</td>" & vbNewLine & _
"<td align=""center"" valign=""middle"" width=16 class=""caltext"">s</td>" & vbNewLine & _
"</tr></table>" & vbNewLine & _
"<table cellpadding=0 cellspacing=1 border=0 bgcolor=""" & session("colourbg3") & """><tr>" & vbNewLine

i = 0
while i <> calmark
i = i + 1
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/caloff.gif"" class=""calnumoff""></td>" & vbNewLine
wend

m = 0
dim arrayevents()

while not events.eof
m = m + 1
redim preserve arrayevents(m)
dd=day(events("event_date"))
arrayevents(m) = dd
events.movenext
wend
events.movefirst


i = calmark
j = 0
k = ""
while i <= 42
i = i + 1
j = j + 1
if j <= LastOfMonth then
if j < 10 then k = "0" else k = "" end if
mydateb = mth&"/"&k&j&"/"&yr
r = 0
q = 0
while q <= j
q = q + 1
if q <= m then
if arrayevents(q) = j and r = 0 then
r = 1
if j = day(date) then
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/calondy.gif""><a href=""index.asp?id=news_and_events&gotodate=" & mydateb & """ onmouseover=""self.status='Click to Launch Event Item'; return true"" onmouseout=""self.status=' '; return true"" class=""calnumondy"">" & k & j & "</a></td>" & vbNewLine
elseif j < day(date) then
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/calonx.gif"" class=""calnumoff"">" & k & j & "</td>" & vbNewLine
else
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/calon.gif""><a href=""index.asp?id=news_and_events&gotodate=" & mydateb & """ onmouseover=""self.status='Click to Launch Event Item'; return true"" onmouseout=""self.status=' '; return true"" class=""calnumon"">" & k & j & "</a></td>" & vbNewLine
end if
end if
end if
wend

q = 0
while q <= j
q = q + 1
if q <= m then
response.write arraycheck
if arrayevents(q) <> j and r = 0 then
r = 1
if j = day(date) then
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/calondy.gif"" class=""calnumoffdy"">" & k & j & "</td>" & vbNewLine
elseif j < day(date) then
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/calonx.gif"" class=""calnumoff"">" & k & j & "</td>" & vbNewLine
else
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/calon.gif"" class=""calnumoff"">" & k & j & "</td>" & vbNewLine
end if
end if
end if
wend
if i = 7 or i = 14 or i = 21 or i = 28 or i = 35 then response.write "</tr><tr>" & vbNewLine end if
elseif (j > LastOfMonth) and (j <= (42-calmark)) then
response.write "<td align=""center"" valign=""middle"" width=16 height=16 background=""graphics/caloff.gif"" class=""calnumoff""></td>" & vbNewLine
if i = 7 or i = 14 or i = 21 or i = 28 or i = 35 then response.write "</tr><tr>" & vbNewLine end if
end if
wend

response.write      "</tr></table>" & vbNewLine & _
"</td></tr>" & vbNewLine & _
"</table>" & vbNewLine
%>
0
Comment
Question by:Jubei01
  • 15
  • 9
  • 6
  • +3
38 Comments
 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 150 total points
ID: 12142110
Ummm, this is too much code for anyone to review, or look at.  This site will help you fix problem....not code analysis in this magnitude.

On eprobelm I see off hand is that you are using alot of session variables that take up resources...ESPECIALLY putting you connection and recordset in session.  BIG NO-NO.

You should be putting you connection in a function or include file and calling it when you need it.  The include file would be put at the top of every page, which would open the connection for the page, and then another include at the bottom of the page to close the connections.  There is absolutely no reason to put this information in session variables.

Example:

<!--#INCLUDE FILE = "../includes/openconnection.asp" -->

<TABLE WIDTH="100%" ALIGN="left" CELLPADDING="0" CELLSPACING="0">
          <TR>
               <td>
                           set rs = server.CreateObject("ADODB.Recordset")
                         SQL = "SELECT * FROM YOURTABLE
                         rs.Open sql, conn, 2,3  '<--------------------CONN IS OPENED IN THE INCLUDE FILE ABOVE
                                   'BLAH BLAH...DO ALL YOUR OTHER STUFF WITH THIS RECORDSET, AND THEN CLOSE CONNECTION IN INCLUDE FILE BELOW
             </td>
        </tr>
 </table>

<!--#INCLUDE FILE = "../includes/closeconnection.asp" -->
              
0
 
LVL 1

Accepted Solution

by:
flatsheep earned 200 total points
ID: 12142862
Another tip: Don't post your scripts to a public website.

Personally I adopt a header/footer include strategy in my asp apps.  That way you can handle any site login or common task in one area.  Within the header include you can include your db includes and function includes.  It makes expanding the site easier.

Don't use the session object to store the connection string... If you want to store it in memory use the application object.  Do this in your DB include.

Storing the Connection object in a session object is a cardinal sin according to Microsoft.  Instead, just create a connection object as a normal variable.  If you have the include file then you can create a global, e.g. gbl_cnnDatabase.    Personally I have functions to perform queries... GetQuery (returns a basic recordset), DoQuery (just executes a sql statement), GetRSByQuery (returns a recordset with a dynamic cursor, so RecordCount and Filter properties work).

Only use the session object when you want to persist data across pages, such as username, real name, etc.  Don't store objects in the session or application scope.

You don't have to Response.write every thing... You can context switch between asp and html:

e.g.

<% If blnCondition Then %>
   This is plain html
<% End If %>

You have to find a good balance.  The above is handy when using an IDE.

Avoid single letter variables. They're meaningless to any other developer, and probably you in 6 months time.  MS conventions for variables in asp are:

intMyVariable

So the first three letters indicate the type of data held in the variable, these can be str (string), rst (recordset), int (integer), obj (object), cnn (connection), cmd (command), etc, etc. This is meaningless to the compiler, but very meaningful for developers! Keep names short, and avoid abbreviating.

COMMENTS COMMENTS COMMENT...

The only reason you should abandon a session is to kill it... I don't think you're using sessions in the way they are meant.  Just use variables.  You would normally only call Session.Abandon for a log out feature, etc.  A session will expire after a default (20 mins) or set period of time anyhow.

That's all I have time for now.

DF

0
 
LVL 15

Expert Comment

by:joeposter649
ID: 12143168
Looks like you got quite a few specific comments on your code so I'll just add a couple links...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasp/html/asptips.asp
http://www.4guysfromrolla.com/webtech/top10/
0
 

Expert Comment

by:trentk2
ID: 12148611
if this is a new project and a 'big' project as you mention why are you writing it in classic asp.  ASP .Net is better - especially if your project is starting from a clean slate.  It makes sense to use the best tool available if you've got no other factors dictating which language you use.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156497
I was expecting the comments about Session Connections.

flatsheep >> You don't have to Response.write every thing... You can context switch between asp and html <<
Doesn't this conflict with
Tip 15: Batch Inline Script and Response.Write Statements
from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasp/html/asptips.asp
I was alway under the impression this was bad.

flatsheep >> The only reason you should abandon a session is to kill it... I don't think you're using sessions in the way they are meant.  Just use variables.  You would normally only call Session.Abandon for a log out feature, etc.  A session will expire after a default (20 mins) or set period of time anyhow.<<
Wouldn't the idea be to close all sessions you don't need straight away? To save system resources. Unless there is alot of overhead on each session connection and closure?

There was a reason to use session in this way but my site has changed enough that i can probably get rid of sessions now.

trentk2 >>
Um because I had a asp text book from back in my uni days and I was to lazy to learn another language. And i'm not really convinced there would be a huge benifit in going with asp.net in this case. But I will probably convert this to asp.net eventually.

Yeah I know that most people are very protective of there script. But i'm not in it to make a profit or whatever else so people can use it if they want. I would be suprised if most people here couldn't code that anyway. Plus this is just the page that generates all the contents. It only represents about 5% of the whole site.

And see I've already learn't something so it's all good! :)

0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156532
So what further questions do you have about your code?
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156538
Oh yeah, and Response.write for your HTML requires more resources than INLINE scripting.  I would recommend using INLINE code instead of Response.write, most of the time.  Much easier to read for formatting purposes/
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156610
Just concerned about the number of database queries you can make for each page generation before things become slugish.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156635
so your saying

this...
<title><%=website_title%> / <%=menu("lvname")%></title>
is better than..
response.write "<title>" & website_title & " / " & menu("lvname") & "</title>"

Sorry, it's just a bit hard for me to accept when there are alot of websites out there that say I shouldn't do that as I've mentioned before.

But I know that you, alorentz, are one of the best so I will change it.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156647
response.write "<title>" & website_title & " / " & menu("lvname") & "</title>"  '<This requires that the Server process everything!

<title><%=website_title%> / <%=menu("lvname")%></title>  This requires that the server only process the variables, the browser does the HTML.

Which do you think is less work for the server? :)


0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156651
>>Just concerned about the number of database queries you can make for each page generation before things become slugish.

There is no prerequisite....depends on your server and memory...etc.  But as far as connections...should only use ONE, the rest are recordsets.  But I would try to limit it to 5.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156676
Quote from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasp/html/asptips.asp

Each of these statements results in writing data to the browser over the network in many small packets. This is slow. Also, interspersing small amounts of script and HTML causes switching between the script engine and HTML, reducing performance. Thus, use the following tip: Replace closely-bunched inline expressions with one call to Response.Write.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156690
True, in closely bunched circumstances...and that is why I said "most of the time".  And this also depends on buffering.  I was refering to your current code, where you are doing all Response.write....which I would not do.  VERY hard to debug, or get an idea of layout for the page.

Maybe just prefernce, but I DO NOT prefer response.write.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156744
Oh I just remembered the real reason why I was using sessions. I have include files that requires a db connection. So if I have my index page with one connection then 2 other include file with another connection each isn't that starting to get bad?
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156774
If they are include files, then they can use the connection you alreay have in the index page.  Include files can use whatever connections are in the main page.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156828
I must be doing something wrong then because it keeps asking for Object required: 'MyConn' in the include file.

This is for the Calendar code that I included above. It is an include file.
<!--#INCLUDE FILE="include/calendar.inc"-->

I have removed all Sessions.

The only thing i can think of is maybe the connection is closing to early. Include files render last, right?
Or should I be using  Server.Execute
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156850
>>Include files render last, right?

Actually they are interpreted FIRST, but ASP is rendered TOP-DOWN.  So, usually the connection is open in an include at the TOP, and then closed at the bottom of the page.  JUST LIKE MY EXAMPLE AT THE TOP.... ;)
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12156853
Opps rather the calendar is using Server.Execute. Because the database decides which includes I want to use.
Not the other way around.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12156891
Well, I've told you all I can... good luck!
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Assisted Solution

by:thefritterfatboy
thefritterfatboy earned 150 total points
ID: 12159019
Just a pointer on the response.write performance issue. This depends on whether or not you have set buffering on or off. If you have not set response.buffer = True at the top of your page YOU SHOULD NOT USE <%=variable%> too much. IIS is absolutely pathetic at sending out packets accross netowrks and every <%=variable%> sends a new packet. Bad move.

Setting Response.Buffer = True is usually the best way to go if you use <%=variable%> a lot. You can always call Response.Flush every so often to flush some HTML to the client.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12159077
Yes, I mentioned buffering in my last post.  For an article on INLINE coding:

http://4guysfromrolla.com/webtech/021302-1.shtml
0
 
LVL 1

Expert Comment

by:flatsheep
ID: 12164788
>>flatsheep >> You don't have to Response.write every thing...
>>You can context switch between asp and html <<
>>>>Doesn't this conflict with
>>>>Tip 15: Batch Inline Script and Response.Write Statements
>>>>from MSDN tips
>>>>I was alway under the impression this was bad.


Hi,

As alorentz pointed out, no this isn't an issue as long as you have buffering enabled.  IIS ships with buffering enabled, and there are only a few applications for switching it off.  The MSDN tip 15 state that it is only an issue with buffering switched off.  I'm not saying that there isn't a small performance hit if you are excessive, but like most things, in moderation it's more beneficial... You typically use buffering when: 1) You want to send a large page or dataset in chunks.  2) You want some sort of real time load bar, due to a slow resource (typically intranet use). 3) Streaming data to the client, after setting the content disposition headers, i.e. file transfer.

You should try to prevent concatenating strings, as this can have a performance hit, especially in loops, under a heavily loaded server.

Get your SQL Server up ASAP, views/functions and Stored procs help speed up data queries, aswell as the connection pooling that SQL server offers.

As others have said, ASP.NET is the way forward.  It allows you to seperate code from presentation.  Plus it's a completely new way of working with website, more structure and integration. c# is my language of .NET, although there are lots of .NET languages out there.

We've all been where you have at some point in coding, forums and code examples are an excellent way to learn.

Good Luck

DF
0
 
LVL 10

Expert Comment

by:thefritterfatboy
ID: 12167811
>>As alorentz pointed out, no this isn't an issue as long as you have buffering enabled.  IIS ships with buffering enabled, and there are only a few applications for switching it off. <<

As far as I'm aware IIS defaults buffering to false. If your scripting has only a few "response.writes" in it - it is VERY good practice to have buffering off so pages load quicker.
0
 

Expert Comment

by:trentk2
ID: 12167846
man how long is this post!!!??
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12167889
Buffering can also be set site-wide in the IIS MMC; site-wide buffering is off by default in IIS 4.0 and on by default in IIS 5.0.
0
 
LVL 10

Expert Comment

by:thefritterfatboy
ID: 12167955
>> Buffering can also be set site-wide in the IIS MMC; site-wide buffering is off by default in IIS 4.0 and on by default in IIS 5.0. <<

Where is that setting?
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12168306
To enable buffering for an ASP application

-In IIS Manager, expand the local computer, right-click the starting-point directory of the application you want to configure, and then click Properties.
-Click the appropriate tab: Home Directory, Virtual Directory, or Directory.
-In the Application settings area, click Configuration, and then click the Options tab.
-On the Options tab, in the Application configuration section, select the Enable buffering check box.
-Click OK.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12168310
<joking>
fritter - do I get extra points for your questions too?
</joking>
0
 
LVL 10

Expert Comment

by:thefritterfatboy
ID: 12168428
Hahaha - If I could I would.

I think that "enable buffering" only enables to ASP scripts to be able to set response.buffer to true. All ASP documentation says that ASP buffering is set to false as default.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12168472
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12168478
Jubei01 - Now that we've all gotten a good amount of information out of this, time to close this one... :)

Good luck!
0
 
LVL 10

Expert Comment

by:thefritterfatboy
ID: 12168639
Good old Microsoft. With IIS 5.0 you get the ASP documentation which quotes:

Syntax
Response.Buffer [= flag]
 
Parameters
flag

Specifies whether or not to buffer page output. It can be one of the following values.

FALSE No buffering. This is the default value. The server sends output to the client as it is processed.  

TRUE The server does not send output to the client until all of the ASP scripts on the current page have been processed, or until the Flush or End method has been called.


I guess it's up to us to find out which documentaion is true. (I have to say, unless otherwise stated, my pages tend to buffer so I think the ASP documentation is wrong.)
0
 
LVL 1

Expert Comment

by:flatsheep
ID: 12173230
>>As far as I'm aware IIS defaults buffering to false. If your scripting has only a few "response.writes" in it - it is VERY good practice to have buffering off so pages load quicker.<<

As this article says, IIS 5.1 and above ship with buffering enabled by default.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/changes_in_asp_features_in_iis_5_1.asp

DF
0
 
LVL 1

Expert Comment

by:flatsheep
ID: 12173282
0
 
LVL 10

Expert Comment

by:thefritterfatboy
ID: 12173825
>> As this article says, IIS 5.1 and above ship with buffering enabled by default.<<

Yeah - we worked that one out. I think it's from 5.0 upwards.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12174854
Well at least I seem to be able to get everyone talking :)

I have gotten rid of Session variables entirely. Which does not work with server.execute so I have to find a work around which requires rewriting the backend a bit. I've made sure response.buffer is enabled just in case it's not!

And i've stumbled upon get getrows which are apparently better than while loops. But I don't really understand them yet.

All this is very stressful. I buy text books which never have what I need to know in them. So I come here and to a few tutorial sites to glean some information from. Which is the biggest help but at the end of the day you still don't know if your doing the right thing because you haven't asked the right question in the first place. It's all baby steps.
0
 
LVL 1

Author Comment

by:Jubei01
ID: 12174883
Thanks guys!
0
 
LVL 1

Expert Comment

by:flatsheep
ID: 12180566
Hi,

I know this thread is finshed, but just regarding your GetRows() in place of For loops, there is some good info here on that:

http://www.learnasp.com/learn/whygetrows.asp

DF
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now