DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Session handling using Objects and Classes

By: rekha singh | 17 Jun 2010 12:05 pm

 Greetings,

 
I am new to OOP PHP. Please guide me how to take care of sessions and cookies using object.
 
What I want is to create a class named session and session functions in it. which can be reused in whole site.
 
Thanks and Regards
 

Comments

Hello,

 
As you said you are new to OOP PHP and want to know about the common functions that one should keep in mind for the site wide usage. So, my thoughts on it is you must consider the below listed items (Member
functions) to make a session and cookie manager class:-
 
a) *ErrorLog()* : First of all make a function for keeping the error log for the class. Which can be called by any member function to keep the log of the any generated by the other functions.
 
b) *setSessionVariable (): *To create a new session value.
 
c) *setSessionVariable (): *To get the value of a session variable.
 
d) *isSessionAlive( ): *To check if a session variable exists or not. You can use isset() function for this.
 
e) *unsetSessionVariab le*(): To kill a session variable. Using unset() of php.
 
f) *destroySession( )* : To destroy the whole session variables at once. You can use session_destroy( ) function for this.
 
g) *getSessionId( )* : This function will be used to get current session Id by using session_id() function.
 
*For Cookies*
 
a) *setCookieVariable( )* : This will help you out to create a new cookie.
 
b) *getCookieVariable( )* : This will help you to get value from a cookie.
 
c) *isCookieAlive( )* : To check if cokkie value/ variable exists or not. same as session isset() function can be used for it.
 
I think that will be good for creating a starting level Common OOP Session/Cookie handler class.
 
Note: Also not forget about the Access specifiers for the member functions. It always helps a lot in large scale applications.
 
Regards,
 
By: rekha singh | 17 Jun 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move