El Phantom Posted August 24, 2009 Share Posted August 24, 2009 Hey Everyone, first post on this forum. I was about to start a login system for a site and was thinking about making it Object based, specifically I was thinking about creating a Login class that i would pass around via a session and which would contain all data pertaining to the user and the logged-in session. As I understand it however, i would have to serialize this login object and place it in a database table or a session variable in order to pass it from page to page. Is this a wise idea, or should i just pass the individual login variables around via the session and forget the object oriented approach? does anybody have any experience they would be willing to share, just wondering if the OO approach is wise if I need a persistent object. I will be using PHP5. Thanks in advance to anyone who answers. --EP Link to comment https://forums.phpfreaks.com/topic/171662-persistent-objects-via-session-good-idea-or-bad/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 24, 2009 Share Posted August 24, 2009 You can create an instance of a class directly in a session variable and as long as the class definition exists before the session_start() you can resume that instance of the class - <?php require 'your_class.php'; session_start(); if(!isset($_SESSION['some_object_name'])){ // create instance $_SESSION['some_object_name'] = new your_class(); echo 'object created<br />'; } else { echo 'object exists<br />'; } $_SESSION['some_object_name']->class_function(); echo $_SESSION['some_object_name']->class_variable; ?> Link to comment https://forums.phpfreaks.com/topic/171662-persistent-objects-via-session-good-idea-or-bad/#findComment-905185 Share on other sites More sharing options...
El Phantom Posted August 24, 2009 Author Share Posted August 24, 2009 sweet, that's good to know, thanks for the input Link to comment https://forums.phpfreaks.com/topic/171662-persistent-objects-via-session-good-idea-or-bad/#findComment-905205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.