| |
| 1 |
Install AO-JD Cookie Methods |
|
|
| 1.1 |
Install client side on HTML page |
|
|
| 1.2 |
Install server side on ASP page |
|
|
| 2 |
Create a Database Cookie Object |
|
|
| 3 |
Database Object Cookie Methods |
|
databaseObject.Method() |
| 3.1 |
.LoadCookie() |
|
Load a cookie into database if present on users
machine |
| 3.2 |
.RemoveCookie() |
|
Remove a cookie from user machine - records etc
still present in database |
| 3.3 |
.SaveCookie() |
|
Save database cookie onto users machine |
| 4 |
Setting cookie values |
|
How to set cookie values. |
| 4.1 |
database.DBaseCookieRecordset |
|
A database cookie has this recordset that you can
use to set cookie values. |
| 5 |
Container Property Object |
|
|
| 5.1 |
database.CookieDBaseProperties |
|
Holds properties for a database object |
|
|
|
| ^ | < > |
1 |
Install AO-JD Cookie Methods |
| |
|
AO-JD was created initially for client side data processing. After working with server side ASP pages I wanted to know if AO-JD
could run server side on an ASP page which it does.
AO-JD cookie methods also work server side and can be used to pass cookie databases about a website. |
| ^ | <
> |
1.1 |
Install client side on HTML page |
| |
|
<script language="JavaScript" src="AccessObject-JavascriptDatabaseV3_47.js"></script>
<script language="JavaScript" src="AO-JD_CookieCodeV2_1.js"></script>
Note: The database must come first.
|
| ^ | <
> |
1.2 |
Install server side on ASP page |
| |
|
<!--#include file="AccessObject-JavascriptDatabaseV3_47.inc"-->
<!--#include file="AO-JD_CookieCodeV2_1.inc"-->
Note:
1) rename file to .inc
2) alter two lines at top and bottom of AO-JD and Cookie files, see AO-JD
and Cookie code for instructions.
3) The database must come first.
|
| ^ | <
> |
2 |
Create a Database Cookie Object |
| |
|
var DB = new Database('DB')
if (DB.CookieLoad()) { //if cookie present the cookie will be loaded
into database
//wait - make sure cookie loaded before continuing
}
Note: the property Loaded from the DBaseCookieProperties container
object will be set to true if loaded else false. see also LoadCookie
method |
| ^ | <
> |
3 |
Database Object Cookie Methods |
| |
|
databaseObject.Method() |
| ^ | <
> |
3.1 |
database.LoadCookie() |
| |
|
The following function is taken from the simple
cookie demo
function DatabaseCreateCookie() {
//pDB is a global database object, iMyCookieVersion is global value set in Initialise()
var foundCookie = false, correctCookie = false;
pDB = new Database('pDB')
if (pDB.CookieLoad()) { //initialise cookie database and load cookie if present
//wait - make sure cookie loaded before continuing
}
if (pDB.DBaseCookieProperties.Loaded == true) foundCookie = true
if (foundCookie) {
pDB.form.MoveFirst()
if (pDB.form.CookieVersion == iMyCookieVersion) correctCookie = true
}
if (!correctCookie) {
pDB = new Database('pDB')
if (pDB.CookieLoad()) {
}
pDB.CreateRecordset('form')
with (pDB.form) {
CreateField('Name')
CreateField('Telephone')
CreateField('Email')
CreateField('Food')
CreateField('Team')
CreateField('Color')
CreateField('CookieVersion') //Note: having this type of field is useful if you ever decide to alter the fields of a recordset
as you may pickup an old version of cookie.
RsetProperties.CookieOn = true //required to save this recordset as a cookie
}
pDB.form.AddRec(['','','',0,0,0,iMyCookieVersion]) //default record
}
objDisplayInformation.Print(getHTML_DisplayInformation())
}
Note: must set RsetProperties.CookieOn to true to save the recordset in
cookie string |
| ^ | <
> |
3.2 |
database.RemoveCookie() |
| |
|
Removes a cookie from users machine although the
database and it's records generated from loading the cookie are not
removed. if (DB.RemoveCookie())
//wait - make sure cookie is removed before continuing
}
The following function is taken from the simple cookie demo. function DatabaseRemoveCookie() {
//pDB is a global database object
if (typeof(pDB) == "undefined") {alert('Remove unsuccessful, you must create a cookie.');return }
if (pDB.DBaseCookieProperties.Loaded == false) {alert('Remove unsuccessful, no cookie to remove.');return }
if (pDB.CookieRemove()) {
//wait - make sure cookie is removed before continuing
}
objDisplayInformation.Print(getHTML_DisplayInformation())
} Note: when cookie removed DBaseCookieProperties.Loaded is set to false
|
| ^ | <
> |
3.3 |
database.SaveCookie() |
| |
|
Saves a database cookie onto users machine
if (pDB.CookieSave()) {
//wait - make sure cookie is saved before continuing
}
The following functions DatabaseSaveCookie() and DatabaseUpdateCookie()
are taken from the simple cookie demo.
function DatabaseSaveCookie() {
//pDB is a global database object
if (typeof(pDB) == "undefined") {alert('Save unsuccessful, you must create a cookie.');return }
DatabaseUpdateCookie() //update recordset fields with form values
with (pDB.DBaseCookieRecordset) {
MoveFirst()
UpdateField('ExpireHours',1) //1 hour
UpdateField('ExpireMinutes',1) //1 minute
}
if (pDB.CookieSave()) {
//wait - make sure cookie is saved before continuing
}
objDisplayInformation.Print(getHTML_DisplayInformation())
}
function DatabaseUpdateCookie() {
//pDB is a global database object
var myform = objForm.Form('userDetails')
with (pDB.form) {
MoveFirst()
UpdateField('Name',myform.Name.value)
UpdateField('Telephone',myform.Telephone.value)
UpdateField('Email',myform.Email.value)
UpdateField('Team',myform.Team.selectedIndex)
UpdateField('Food',myform.Food.selectedIndex)
for (var i=0; i<myform.Color.length; i++) {
if (myform.Color[i].checked == true) {
UpdateField('Color',i)
break
}
}
}
} |
| ^ | <
> |
4 |
Setting cookie values |
| |
|
When you create a cookie database you also create
a cookie recordset (DBaseCookieRecordset) whose fields are standard cookie variables such as
expires. see 4.1 and 3.3 |
| ^ | <
> |
4.1 |
database.DBaseCookieRecordset |
| |
|
Use UpdateField method to change field values before saving. see 3.3
| fieldname |
|
information |
| Domain |
|
cookie domain information |
| ExpiresHours |
|
cookie expires in hours |
| ExpiresMinutes |
|
cookie expires in minutes |
| Path |
|
cookie path information |
| Secure |
|
cookie secure information |
|
| ^ | <
> |
5 |
Container Property Object |
| |
|
A container property object contain properties that
reflect various states of the database, in the following case the cookie
state of the database. |
| ^ | <
> |
5.1 |
database.DBaseCookieProperties |
| |
|
database.DBaseProperties contains the following properties:
| property name |
read/write |
type |
information |
| AOJDCookieVersion |
r |
string |
current version of cookie code |
| Domain |
r |
string |
internal |
| Expires |
r |
string |
internal |
| ExpireHours |
r |
integer |
internal |
| ExpireMinutes |
r |
integer |
internal |
| Path |
r |
string |
internal |
| Secure |
r |
boolean |
internal |
| Document |
r |
object |
document object |
| CookieString |
r |
string |
string representation of cookie |
| CookieLength |
r |
integer |
length of cookie in bytes - add about 150
for real size |
| Loaded |
r |
boolean |
whether a cookie has been loaded into
database |
| Note the following separators
are used internally to separate data. Although marked as 'r' - read
only, you could change if wished. see code for default values or
simple cookie example. |
| SeparatorDBName |
r |
string |
database name |
| SeparatorFieldNames |
r |
string |
field names |
| SeparatorFielddbIndex |
r |
string |
fields indexed (dbPrimaryKey) |
| SeparatorFieldType |
r |
string |
field types |
| SeparatorFieldValues |
r |
string |
field values |
| SeparatorRecords |
r |
string |
record values |
| SeparatorRsets |
r |
string |
recordsets |
| SeparatorRsetDefinition |
r |
string |
recordset definition information |
| SeparatorEnd |
r |
string |
end of cookie string |
|