|
hyBook - A Simple Guestbook Application
Part:
1
2
3
4
5
6
7
8
9
10
11
12
13
(Continued from previous part...)
Configuration File
The easiest way to set up configuration files with ASP pages is to use include files. For hyBook,
I used one include file, _config.inc, to maintain all configurable items:
<%
' _config.inc
'
' Configuration file
' hyBook version 2005.12.11
' Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/
' Database connection
Dim ogConn
Set ogConn = Server.CreateObject("ADODB.Connection")
' Number of submits per IP per day
Dim ngSubmitLimit
ngSubmitLimit = 10
' Default topic ID
Dim ngDefaultTopicID
ngDefaultTopicID = 14
' Page title
Dim sgPageTitle
sgPageTitle = "hyBook Demo"
' Debugging flag
Dim bgDebug, ogDebug
bgDebug = False
Set ogDebug = Nothing
Sub dbConnect
ogConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("/cgi-bin/hyBook.mdb")
If bgDebug Then
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set ogDebug = oFileSys.OpenTextFile("\temp\hyBook.log", 8, True)
ogDebug.WriteLine("Open data base connection.")
End If
End Sub
Sub dbClose
Set ogConn = Nothing
If bgDebug Then
ogDebug.WriteLine("Close data base connection.")
ogDebug.Close
End If
End Sub
%>
Note that:
- All variables defined in _config.inc should be global variables so they become accessible in any functions
in any ASP pages. A "Dim" statement is needed to make a variable global.
- Database connection process should be a configuration item, because it is always different from one Web
server to another.
- I also included a debug flag in the configuration file to control printing debug information in a log file.
(Continued on next part...)
Part:
1
2
3
4
5
6
7
8
9
10
11
12
13
|