Wrox Programmer Forums
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 5th, 2004, 08:13 AM
Authorized User
Join Date: Sep 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default Session vs. "global" variables

Hi, all,

I'm trying to use a variable that can be passed and used by all Functions/SUBs in the same page. While exploring the options, I wonder the plus and minus of using session variables and a "global" variable which I declare it on the top and pass it as parameters to all subroutines? It seems to me one is slower than the other?


Old October 5th, 2004, 08:04 PM
Friend of Wrox
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post


  I think that wont be cinsiderable slow.


Old October 5th, 2004, 08:21 PM
Friend of Wrox
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41

Does this variable change? If not I would use a constant.
Rather than declaring it on every page, you could EG:

Create a file called globalConstants.inc, this file would hold your constant(s). Then place an include on every page to this file.

An example of how I use this file:
I create constants for UserName, Password, DBName and machineName. These constants are used in my globalFunctions file in my SQLServer connection string, this globalFunction file is also an include on every page that needs a database connection.

;;;I wonder the plus and minus of using session variables
Use these sparingly. What I use them for:
A variable that has the ability to change, needs to be carried from page to page and it's not practical to use hidden form variables (num 1 choice) or query strings (number 2 choice)

;;;and a "global" variable
A session variable is a global variable, (different in PHP)

Wind is your friend
Old October 6th, 2004, 07:10 AM
Authorized User
Join Date: Sep 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for your guidelines. This all should help!

Similar Threads
Thread Thread Starter Forum Replies Last Post
global variables Komila ASP.NET 3.5 Basics 2 October 31st, 2008 01:14 PM
Global Variables in C# su C# 2 December 11th, 2006 06:18 PM
Global variables zarol Beginning PHP 3 May 10th, 2005 06:17 AM
Global Variables in .NET mbmsecret C# 5 July 6th, 2004 02:27 AM
Global variables ps124 ASP.NET 1.0 and 1.1 Basics 6 April 6th, 2004 02:48 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.