Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Cookies Vs. Sessions
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Spoon
Average Member

Ireland
507 Posts

Posted - 20 July 2001 :  17:56:02  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
Hi,

im making an app that uses sessions and cookies. I only use the session for 4 small text strings, username, password, userlevel and userid.

I use cookies for some larger stuff like copyrightstatments, Pagetitle, styles

Which consumes more server resources, will the sessions cause problems if too many users are active? Am i worrying over nothing?

Any help is greatly appreciated





Regards,

Spoon, (ya all love me right?)

Id
Junior Member

USA
129 Posts

Posted - 20 July 2001 :  18:04:28  Show Profile  Visit Id's Homepage
if it's something small and simple like username and the like it's probably faster to store it in a session variable, because when it's stored in a session variable it's cached on the server, which means it doesn't have to do a query to your computer for the cookie and then act accordingly, it can just take the data it has on it's end, and then use it. if you have a fast connection you probably won't notice a difference, but for slower modem users, if it's stored in a session variable, the pages will probably load better for them. And being that they're just really small simple strings, it's not going to take up server resources. There's a link floating around the board with tips on how to optomize asp pages, and one of them is to store commonly used data in session variables, which is what you're doing with these guys :)

Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 20 July 2001 :  18:41:41  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
quote:

if it's something small and simple like username and the like it's probably faster to store it in a session variable, because when it's stored in a session variable it's cached on the server, which means it doesn't have to do a query to your computer for the cookie and then act accordingly, it can just take the data it has on it's end, and then use it. if you have a fast connection you probably won't notice a difference, but for slower modem users, if it's stored in a session variable, the pages will probably load better for them. And being that they're just really small simple strings, it's not going to take up server resources. There's a link floating around the board with tips on how to optomize asp pages, and one of them is to store commonly used data in session variables, which is what you're doing with these guys :)





Thx for the advice ID,

One thing though, would it better for me to stick the slightly larger stuff into the sessions aswell, ( i mean the things stored in cookies as mentioned above.)

Thanks Id


Regards,

Spoon, (ya all love me right?)
Go to Top of Page

Id
Junior Member

USA
129 Posts

Posted - 20 July 2001 :  18:53:37  Show Profile  Visit Id's Homepage
Well i guess it depends on what you were planning on putting in the session variable, pagetitles, you'd probably be ok using, i'd stay away from copyright statements though, they tend to get large, styles, i'm not sure about that one either, that could really depend on how large you were planning on making them, if they were really only a one line thing, you probably wouldn't have any problems.

As I understand it, session variables are really designed to be used repeatedly across the entire page, and being that they do take up server resources you want to try and keep them small. My suggestion is, if it's going to be about a line of text, and it'll be used repeatedly throughout the life of the session, then go with a session variable, otherwise you'd probably want to look into other means of collecting your data, either with cookies, or possibly database usage.

Go to Top of Page

gor
Retired Admin

Netherlands
5511 Posts

Posted - 20 July 2001 :  19:09:20  Show Profile  Visit gor's Homepage
Hi Spoon,

quote:

I use cookies for some larger stuff like copyrightstatments, Pagetitle, styles


Why do you want to store them in cookies ?
Are they userspecific ?
And if they are not userspecific, why not user application variables instead ?

quote:

Which consumes more server resources, will the sessions cause problems if too many users are active? Am i worrying over nothing?


That depends on the amount of info you store in the session variables and the amount of users.
Cookies have a sizelimit (don't know exactly what it was), but the total size of cookies allowed on a users harddisc is limited.
On the other hand, if you need to have very much info per user around, you better store it in a database and retrieve it when needed instead of using sessionvariables. Otherwise you'll soon run out of memory.

Pierre
Join the Snitz WebRing
Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 21 July 2001 :  08:08:31  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
quote:

Hi Spoon,

quote:

I use cookies for some larger stuff like copyrightstatments, Pagetitle, styles


Why do you want to store them in cookies ?
Are they userspecific ?
And if they are not userspecific, why not user application variables instead ?

quote:

Which consumes more server resources, will the sessions cause problems if too many users are active? Am i worrying over nothing?


That depends on the amount of info you store in the session variables and the amount of users.
Cookies have a sizelimit (don't know exactly what it was), but the total size of cookies allowed on a users harddisc is limited.
On the other hand, if you need to have very much info per user around, you better store it in a database and retrieve it when needed instead of using sessionvariables. Otherwise you'll soon run out of memory.

Pierre
Join the Snitz WebRing



Hi gor, (THanks for the advice too ID )

Well the styles and copyright arent user specific, i just didnt want to open another recordset for every page. I already open roughly 2 or 3 on each page.

By using cookies i can pass the info on without making another connection on each page. When the user logs in, all the nexessary connections are made and thats the end of it.

Do you think i should just call the copyright and styles from the database on each page??

Thanks in advance,

Spoon

Regards,

Spoon, (ya all love me right?)
Go to Top of Page

gor
Retired Admin

Netherlands
5511 Posts

Posted - 21 July 2001 :  08:17:42  Show Profile  Visit gor's Homepage
quote:

Well the styles and copyright arent user specific, i just didnt want to open another recordset for every page. I already open roughly 2 or 3 on each page.

By using cookies i can pass the info on without making another connection on each page. When the user logs in, all the nexessary connections are made and thats the end of it.

Do you think i should just call the copyright and styles from the database on each page??



No, but you could use the Application() object like we do in config.asp to store all the colors, settings etc. for the forum.
There you see that they get loaded once (1 application object exist per total asp application, while each user has his/her own session object), and then gets used in all the other pages.
That way you save memory (compared to sessionvariables) and don't have to hit the database with every pageload.


Pierre
Join the Snitz WebRing
Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 21 July 2001 :  10:57:26  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
quote:

quote:

Well the styles and copyright arent user specific, i just didnt want to open another recordset for every page. I already open roughly 2 or 3 on each page.

By using cookies i can pass the info on without making another connection on each page. When the user logs in, all the nexessary connections are made and thats the end of it.

Do you think i should just call the copyright and styles from the database on each page??



No, but you could use the Application() object like we do in config.asp to store all the colors, settings etc. for the forum.
There you see that they get loaded once (1 application object exist per total asp application, while each user has his/her own session object), and then gets used in all the other pages.
That way you save memory (compared to sessionvariables) and don't have to hit the database with every pageload.


Pierre
Join the Snitz WebRing



Thanks gor, ill look into it right now


Regards,

Spoon, (ya all love me right?)
Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 21 July 2001 :  16:13:50  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
Gor,

I tried the application thingy after studying it. My script ran without a problem, well most of it. I did like you did in config.asp - If app("pageloaded") = "" then load the app variables. Below is my bit of code

-----------------------------------------------------


If APPLICATION("PAGELOADED") = "" OR IsNULL(APPLICATION("PAGELOADED")) Then

SQL = "SELECT * FROM SETUP"
SET PMRSTWO = PMDB.Execute(SQL)

APPLICATION.LOCK
APPLICATION("PAGETITLE") = PMRSTWO("SETUPPAGETITLE")
APPLICATION("STYLES") = PMRSTWO("SETUPSTYLES")
APPLICATION("COPYRIGHT") = PMRSTWO("SETUPCOPYRIGHT")
APPLICATION("NAME") = PMRSTWO ("SETUPNAME")
APPLICATION("HOMEPAGE") = PMRSTWO("SETUPHOMEPAGE")
APPLICATION("PAGELOADED") = "YES"
APPLICATION.UNLOCK

PMRSTWO.close
Set PMRSTWO = NOTHING

SETUPPAGETITLE = APPLICATION("PAGETITLE")
SETUPSTYLES = APPLICATION("SETUPSTYLES")
SETUPCOPYRIGHT = APPLICATION("SETUPCOPYRIGHT")
SETUPNAME = APPLICATION("NAME")
SETUPHOMEPAGE = APPLICATION("SETUPHOMEPAGE")

End If


---------------------------------------------------------------------------------------

now on any page where i put <%=SETUPPAGETITLE%> or anything that i have just declared, nothing shows up. The database is not empty.

Any ideas on what i am doing wrong??

Thanks



Regards,

Spoon, (ya all love me right?)
Go to Top of Page

gor
Retired Admin

Netherlands
5511 Posts

Posted - 21 July 2001 :  16:28:23  Show Profile  Visit gor's Homepage
Spoon,

You need to set the "normal" variables at every page-load, even though you have to set the application variables only ones per change of the setup.
Try this:



If APPLICATION("PAGELOADED") = "" OR IsNULL(APPLICATION("PAGELOADED")) Then

SQL = "SELECT * FROM SETUP"
SET PMRSTWO = PMDB.Execute(SQL)

APPLICATION.LOCK
APPLICATION("PAGETITLE") = PMRSTWO("SETUPPAGETITLE")
APPLICATION("STYLES") = PMRSTWO("SETUPSTYLES")
APPLICATION("COPYRIGHT") = PMRSTWO("SETUPCOPYRIGHT")
APPLICATION("NAME") = PMRSTWO ("SETUPNAME")
APPLICATION("HOMEPAGE") = PMRSTWO("SETUPHOMEPAGE")
APPLICATION("PAGELOADED") = "YES"
APPLICATION.UNLOCK

PMRSTWO.close
Set PMRSTWO = NOTHING
End If
SETUPPAGETITLE = APPLICATION("PAGETITLE")
SETUPSTYLES = APPLICATION("SETUPSTYLES")
SETUPCOPYRIGHT = APPLICATION("SETUPCOPYRIGHT")
SETUPNAME = APPLICATION("NAME")
SETUPHOMEPAGE = APPLICATION("SETUPHOMEPAGE")

End If




Pierre
Join the Snitz WebRing
Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 21 July 2001 :  16:43:39  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message


What a silly idiot i am,

Thanks for the help gor.



Regards,

Spoon, (ya all love me right?)
Go to Top of Page

gor
Retired Admin

Netherlands
5511 Posts

Posted - 21 July 2001 :  16:46:26  Show Profile  Visit gor's Homepage
You're welcome

Pierre
Join the Snitz WebRing
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07