TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-04-2009, 06:54 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default Session class....

I did a search and didn't find much about this so I'd like to ask...


As I try to implement more OO code into my everyday life. I am struggling to find the benefits of creating a session class...

Here is how I normally use sessions...(small snippit of course)

My main header file starts the session so it is available on all pages that include the header file...

session_start();


As the user successfully logs in, I create a session for them that would include your basic needs, info taken from the DB...

(SQL query and results)

$_SESSION['username'] = $rows["username"];
$_SESSION['userid'] = $rows["userid"]

etc etc....



So that's about it. As I need to access the username, I just simply access the superglobal array throughout the site...

ex:
echo "Username: " . $_SESSION['username'];




I read a good OLD post just now from Xenon about not trying to make everything you do in OO....and I do think that makes sense too...

So is making a session class overkill? Are there any benefits to it especially since it's a superglobal array that I can access anywhere on the site by just calling: $_SESSION[]...

Am I not seeing the bigger picture because I'm using it in such a basic way?

Thanks!
allworknoplay is offline  
Reply With Quote
Old 05-04-2009, 09:57 PM   #2 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Ok so here's an example....say I want to access a session variable the "procedural way"..

echo "$_SESSION['username']";



The OOP way:


function getVar($varName)
{
return $_SESSION[$varName];
}

echo $session->getVar(username);


It almost seems like going out of your way to use OO for session data?
allworknoplay is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
storing class instance into session nizzy Advanced PHP Programming 3 10-02-2008 06:49 AM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Understanding the Life of a Session Wildhoney General 6 10-27-2007 02:34 AM


All times are GMT. The time now is 02:46 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design