|
Application Variables by
Charles Carroll
There are two kinds of data that your program
can manipulate that can be used to "remember" data:
Session data
which is
"attached" to a person browsing your site. If the same page is
accessed by 12 different users each user may have totally different session
values.
Application data
which is
attached to the webserver and is the same no matter which user is accessing
the site.
Application values are visible to every user.
But since, unlike session data, any web page could change the application's data there is
a potential concurrency issue. The lock and unlock method of the application object
eliminate concurrency issues. Once an application is locked, no other updates to the
application object can occur until the unlock is executed. One
use for an application variable would be to store variables most scripts on a
site needed to access or even HTML cached from databases like in
The Worlds Fastest Listbox Example @
http://www.learnasp.com/freebook/asp/speedappdata.aspx
One example I use to illustrate the conceptual
use for each type of data would be a website that simulated a casino. Player's individual
winnings make perfect sense to maintain in session variables. However, the total number of
players at each "virtual table" (blackjack, roulette, etc.) would be application
data as the would be the same regardless of an individual player's status.
Here is a file called appblackjacklook.asp
that displays how many people are at the table.
filename=/learn/test/appblackjacklook.asp
<%
response.write "Over at the BlackJack Table<br>"
response.write "There are " & application("bjplayers") & " players there!<br>"
%>
Here is a file called appblackjackarrive.asp
that could be included in any script where someone arrived at the blackjack
table!
filename=/learn/test/appblackjackarrive.asp
<%
response.write "Welcome to the BlackJack Table<br>"
application.lock
application("bjplayers")=application("bjplayers")+1
application.unlock
response.write "There are " & application("bjplayers") & " players here!<br>"
%>
Here is a file called appblackjackleave.asp
that could be included in any script where someone left the blackjack table!
filename=/learn/test/appblackjackleave.asp
<%
response.write "Thanks for playing BlackJack!<br>"
application.lock
application("bjplayers")=application("bjplayers")-1
IF application("bjplayers")<0 THEN
application("bjplayers")=0
END IF
application.unlock
response.write "There are " & application("bjplayers") & " players still at the table!<br>"
%>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|