Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Session Management with PHP4
So, What Does This Do For Me?
Legitimate question. There are too many ways to use session management and session variables to include them all here, but I'll give you an example. Say you're building a community site, like I've been doing, you might want to keep the name of the currently authenticated user and perhaps how many new messages he's got. In order to keep the load off the database you're using, you want to cache the number of messages. You could do this two ways;
  1. You could use three cookies:
    • authenticated_user - The currently authenticated username (or id)
    • num_messages - The number of messages he's got
    • expire_time - When to recache the number of messages
  2. Use sessions and register three session variables.
The first method limits security, someone can fake the cookies and virtually get access to another user's account. It's messy because of all the Header() calls you need to do, it's overall ugly, and you might get inconsistent data in case the user refuses to accept one of the cookies.
With sessions, the user only has to accept one cookie, you keep much better consistency in your data and you get a bit more security.
Drawbacks
Session gives you freedom, flexibility and functionality that is assiciated with any good serverside scripting language. Though, PHP4 session has a few limitations; first off all, you cannot store objects in the sessions, which would have been absolutely fantastic, just imagine storing a complete user object in the session.. Second, storing data in session variables is not very efficient because PHP4 is using files to store session information, but overall I'm very satisfied with how PHP4 session management works.
Try it out - you'll like it.

[Page 1]  [Page 2]  


Comments:
Assistshafeeq04/10/07 01:18
RE: /tmp/mysql.sock ERROR sessionPranav12/10/05 07:43
Getting session valueJacob11/25/04 07:41
RE: questionrakheeb02/24/04 00:21
RE: Storing objects in sessionsJohn Pierce07/23/03 20:31
RE: IE6 not destroying sessionsDarren06/19/03 12:20
RE: failed to write session data..Oscar F. Duron01/25/03 00:16
Sessions & "Remember Me" cookieSyberius10/24/02 13:04
session managementsuma10/10/02 04:09
Storing objects in sessionsPavel Steinl09/15/02 12:35
file upload not workingswanand09/09/02 03:36
session perform diff Internet and IntranetAndrew09/03/02 04:01
RE: IE6 not destroying sessionsm.strijbos09/02/02 09:44
RE: session_id() issuem.strijbos09/02/02 09:39
No Values in my $_SESSION[] array..........Vamshi08/19/02 05:01
Session_destroy, new session_idDavid Cervetti08/16/02 15:57
write session file problemFabio R Segundo08/14/02 15:55
RE: Problems with accessing session variablesmichael08/07/02 01:40
/tmp/mysql.sock ERROR sessionNilson07/23/02 14:32
session_destroy() not called on browser closeWayne Cope07/21/02 13:50
session_id() issuekasimodo07/16/02 03:27
RE: how to redirect?coffee07/11/02 06:00
RE: Warning: Open(/var/tmp/sess(#$&*#Tim Wesoly07/10/02 07:03
RE: IE6 not destroying sessionsJohn Young07/09/02 00:07
RE: Session ID in the URL+SE unfriendly issuejohn07/04/02 21:00
RE: Session OverwrittenDo Minh Duc06/28/02 02:17
RE: new session_idDo Minh Duc06/28/02 01:39
Warning: Open(/var/tmp/sess(#$&*#Bryan06/18/02 19:22
Session ID in the URLAram06/13/02 07:36
new session_idMartin05/28/02 12:23
what is phpfariba05/28/02 02:51
RE: Session OverwrittenRam Dongre05/22/02 07:42
Session ProblemRam Dongre05/22/02 01:35
Session Overwrittenlaypeng05/02/02 04:34
sesseion managementVishi04/24/02 07:08
Passing Sessions - HELP!Phil Powell04/18/02 12:33
how to redirect?chen04/18/02 12:26
Session ManagementCharlie04/17/02 04:52
RE: session write errorTim04/11/02 17:12
RE: SessionVariable not accessibleDo Minh Duc04/11/02 01:28
SessionVariable not accessibleGali04/10/02 13:56
RE: include files and other files..?Hasangi04/08/02 05:04
PHP 4.1.2. session problemsChrisy03/27/02 05:09
session write errorGerman O03/21/02 15:27
flatDBfile and sesionsFrank Schellenberg03/20/02 12:55
RE: Doing Something wrong Environment variables?Session bugs in 4.1.203/19/02 09:06
RE: session write error ???Session bugs in 4.1.203/19/02 08:26
Session failedwayan03/18/02 02:23
RE: session variable access problemXaver03/15/02 13:20
RE: How to store objects in SessionWill Steffen03/14/02 08:40
IE6 not destroying sessionsgary weir03/11/02 10:00
RE: How can i check if a user had been inactive?Birger Kung03/07/02 11:33
Session Management ObjectFend0r03/03/02 16:06
How can i check if a user had been inactive?tushar02/12/02 15:20
arrays in sessionshahjahan02/06/02 05:50
Secciones en php 4Yordankis Fernandez02/04/02 14:51
RE: session variable access problemkor01/28/02 05:46
session variable access problemdeepak01/22/02 23:43
Problems with accessing session variablesapairudin01/20/02 22:54
Cant Override Session-VarsJakob Külzer01/20/02 06:36
RE: IP DisplaySamhain01/17/02 10:41
IP DisplayBorn2fly01/13/02 08:47
RE: session write error ???Randy12/28/01 14:12
RE: session variablesTodd12/23/01 21:35
Passing Variable To Another PageAsmadi Ali12/22/01 03:06
session variablesRichard Williams12/19/01 20:18
AuthenticationUmashankari12/18/01 22:16
sessionflashcool12/17/01 04:36
session write error ???Rob12/11/01 19:45
questionsantiago11/29/01 18:24
Help?Jitendra11/26/01 08:32
RE: Problem to access History pagesVelimir Sanjkovic11/22/01 11:05
SessionID remainsMichaelV11/17/01 04:37
RE: failed to write session data..Parinda11/15/01 06:28
RE: Doing Something wrong Environment variables?progenius11/13/01 16:53
Please!! someone HELP ME!!David T11/11/01 19:29
Problem to access History pagesHardik11/11/01 12:04
Sessions - Soo Slow...Ran10/29/01 21:55
Retrieving Session VariablesJimin Bhuptani10/24/01 11:40
Class, Function as SessionSmileBit10/16/01 09:57
It worked the first time...TekFox10/02/01 19:13
Doing Something wrong Environment variables?Ben09/30/01 19:45
RE: Session errorbadchenn09/10/01 17:04
RE: Interesting session troublesBrad G09/09/01 14:21
what do i need php for daily jobsachinras4e09/09/01 11:49
Interesting session troublesBrad G09/06/01 10:51
Session errorJules NKAMLA TENE08/25/01 15:13
Belo Artigo. Faltou um exemplo.Jonas A. Lima08/19/01 11:24
RE: session_start, and the loss of data in cJuju08/16/01 12:10
failed to write session data..phil08/15/01 11:36
storing, retrieving objects and fatal errorsJonathan08/09/01 19:09
Tks for writing this articlesanjukta08/06/01 02:06
Session - connection_abortedTay08/05/01 20:56
unsupported or undefined function session_staSteve07/25/01 03:57
what means the session in php it doesn´t gufen07/24/01 08:11
Help, Session_start ErrorMulianto07/20/01 07:48
RE: Problem with session_start() (PHP4)Praveen07/19/01 21:44
How to store objects in SessionRon MacNeil07/11/01 12:20
enqueryghanshyamlalwani07/06/01 21:23
RE: it is realy not secureFlanders07/05/01 03:04
RE: no objects in sessions?hattworks06/28/01 10:44
RE: session_start, and the loss of data in cMario Salinas06/21/01 22:27
Sessions in N4.7Ryan06/08/01 19:44
Session ManagementJim Henderson05/26/01 05:36
no objects in sessions?Patrik05/25/01 10:03
session_start, and the loss of data in cacheEugene Shull05/22/01 06:19
Destroying Sessions??Andrew05/21/01 17:46
Help needed with session variablesChunhui05/16/01 09:57
RE: Session management in PHP4 vs PHPLIBphil3k04/29/01 15:09
Session startMahendran04/20/01 15:45
RE: Problem with session_start() (PHP4)Glan04/18/01 06:48
RE: Problem with session_start() (PHP4)Chunguis04/17/01 02:19
Problem with session_start() (PHP4)Eduard04/12/01 06:30
global sessionkeyur04/06/01 07:01
serializing arrays into sessions...Christian Dechery03/29/01 21:24
RE: a simple example neededfahad03/29/01 11:50
Session with Frame?why03/26/01 22:37
RE: Can you Help me?(about session)Eric Blade03/26/01 12:06
RE: --enable-trans-sid problem.Eric Blade03/26/01 12:03
RE: Privacy and Session Management Eric Blade03/26/01 12:02
RE: Session variables and associative arraysEric Blade03/26/01 11:56
RE: it is realy not secureEric Blade03/26/01 11:53
RE: Drawbacks for loadbalanced WWW servers..Eric Blade03/26/01 10:09
A nice articleJohn Asendorf03/22/01 15:03
Sessions existing DBWayneK03/15/01 22:47
RE: include files and other files..?Jani Kaarela03/13/01 05:58
RE: session_destroy();Jani Kaarela03/13/01 05:55
Can you Help me?(about session)Jun03/12/01 01:14
RE: Help required with sessionsphpcoder03/06/01 03:40
RE: error w/ session startJeremy03/02/01 15:17
include files and other files..?Chris02/27/01 22:39
session_save_path()till topf02/27/01 13:23
error w/ session startDana02/26/01 20:08
session.save_pathdiane02/21/01 16:17
Back will data missingAddison02/17/01 07:07
RE: session_destroy();Aaron02/10/01 06:37
--enable-trans-sid problem.Oskar Edespong02/08/01 14:36
RE: session_destroy();Kwok02/06/01 07:25
Privacy and Session Management Jeremy Castro01/30/01 13:32
RE: Help required with sessionsTom Garcia01/29/01 17:29
Help required with sessionsTabish01/25/01 10:08
Session variables and associative arraysRichard Luck01/09/01 19:29
it is realy not securematwej01/04/01 15:39
RE: instantiate class into session variableSam Nicholson01/02/01 21:37
Problems using MM for session dataSimon Greaves12/27/00 08:34
RE: What happens when Browser window is closed?numeric12/06/00 20:13
sessions (PHP4 & Flash)céline jaume11/30/00 05:55
What happens when Browser window is closed?Ranjith11/20/00 04:19
RE: a simple example neededMauricio Strello11/16/00 10:29
send session variable?Bea11/08/00 12:27
a simple example needednaveen lartius11/06/00 23:11
session_destroy();Bryan 10/09/00 18:01
RE: Drawbacks for loadbalanced WWW servers..Mattias Nilsson09/13/00 17:06
RE: Session management in PHP4 vs PHPLIBPeter09/05/00 17:42
instantiate class into session variableRyan Thomas08/21/00 10:55
RE: Drawbacks for loadbalanced WWW servers..Jordan Husney08/13/00 20:12
Drawbacks for loadbalanced WWW servers..Nate07/09/00 23:06
Session management in PHP4 vs PHPLIBPete07/06/00 10:04
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.