Quantcast
Channel: West Wind Message Board Messages
Viewing all articles
Browse latest Browse all 10393

Re: Scope of variables

$
0
0
Re: Scope of variables
Web Connection
Re: Scope of variables
04/20/2012
02:24:09 PM
3HF0UVEP7 Show this entire thread in new window
Gratar Image based on email address
From:
Rick Strahl
To:
Attachments:
None
Potter,

You can't use 'global' variables in FoxPRo code to track users. Since many users access the same server and the same program they'd all share that same global variable and the results you'd get would not pertain to a specific user. That's a big no-no.

Globals CAN work if you have objects that can be shared. Good examples for this are things like a wwSql instance that can be shared (to avoid re-connecting to a SQL Server, a configuration class, global constants etc. etc.)

For any user storage that needs to persist across hits you can use either HTTP Cookies which is a low level operation you can manage yourself with Response.AddCookie() or Request.GetCookie() which stores single cookie values, or by using the wwSession class (Session to Server.oSession) which uses cookies but provides an easier storage mechanism for many values.

Ideally Session and/or Cookies should only be used to store very simple things like IDs that identify users, which you can use to load up more information from the database/your application. Don't store large pieces of data in there.

As Ian pointed out - take a look at the wwSession class in the documentation which should get you started and you cna then post here for more info.

+++ Rick ---



I am still/again confused about this stateless nature of the Web application and in particular scope issues. When the user comes to my site, I force him to login with an e-mail address and password, look them up in a FoxPro table and determine what kind of access they should be allowed. How do I create memory variables or an object that will remain in scope in the various code behind programs throughout the users session? If I create a variable in the top-level Web connection executable, I presume it will remain in scope throughout, but will each individual visiting the website have their own set of these top-level variables?



Rick Strahl
West Wind Technologies

Making waves on the Web

from Maui, Hawaii

Viewing all articles
Browse latest Browse all 10393

Trending Articles