This section describes the configuration file in ASP script to be used as an include file for the main ASP script page.
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.