[PHP] Sessions and Objects using PHP4
I have RTFM and TTFE and still am having a heck of a time getting my objects to play well between pages The only real examples are in the notes for classes objects http://us2.php.net/manual/en/language.oop.php Basic usage ? include_once(config.inc); include_once(class.php); $songbook = new songbook(); // defined in the class.php session_register('songbook'); $songbook-get_stats(); $songbook-populate_manu(); $songbook-populate_series(); if (!isset($songbook-userid) || $songbook-userid == ) { header(Location: login.php); } Now the login.php is basically the same but if the login correctly it should set $songbook-userid to the username require('common.php'); session_start(); include_once(class.php); $songbook = new songbook(); session_register('songbook'); include(newheader.php); if ( isset($_POST['submitit'])) { $link = dbconnector(); $sql = select * from userinfo where lower(username)=lower('.$_POST['user'].') and lower(password)=lower('.$_POST['pass'].'); $result = mysql_query($sql); if( mysql_num_rows($result) 0 ) { $songbook-userid = strtolower($_POST['user']); header(Location: green.php); } else { $errormsg = font size=3Invalid Username or Password.br\nPlease Try Again./font; } } So I guess what I am asking is how DO you make objects work across pages? -Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessions and Objects using PHP4
David OBrien wrote: I have RTFM and TTFE and still am having a heck of a time getting my objects to play well between pages The only real examples are in the notes for classes objects http://us2.php.net/manual/en/language.oop.php (are you on php4 or php5 btw?) Basic usage ? include_once(config.inc); include_once(class.php); indeed, you must include classes for objects stored in a session before starting the session. :-) $songbook = new songbook(); // defined in the class.php if you are creating this object on every page/call and then assigning it to the session it will always have a blank/null userid. because each call overwrites the old object thats stores with a brand new one. so you need to check the session to see if a songbook object is already available. so you only ever see the login screen in your example. session_register('songbook'); alternative is using $_SESSION. but if you do you must call session_start() first: session_start(); if (!isset($_SESSION['songbook']) || !is_object($_SESSION['songbook']) || !(get_class($_SESSION['songbook']) == 'songbook')) { $_SESSION['songbook'] = new songbook; } $songbook-get_stats(); $songbook-populate_manu(); $songbook-populate_series(); if (!isset($songbook-userid) || $songbook-userid == ) { header(Location: login.php); } Now the login.php is basically the same but if the login correctly it should set $songbook-userid to the username require('common.php'); session_start(); include_once(class.php); $songbook = new songbook(); session_register('songbook'); include(newheader.php); if ( isset($_POST['submitit'])) { $link = dbconnector(); $sql = select * from userinfo where lower(username)=lower('.$_POST['user'].') and lower(password)=lower('.$_POST['pass'].'); $result = mysql_query($sql); if( mysql_num_rows($result) 0 ) { $songbook-userid = strtolower($_POST['user']); header(Location: green.php); } else { $errormsg = font size=3Invalid Username or Password.br\nPlease Try Again./font; } } So I guess what I am asking is how DO you make objects work across pages? -Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions and objects
I create a new object and then assign it to a session var $customer = new Customer($_GET['facilityID'], $_GET['customerID']); $_SESSION['acceptPayment']['customer'] = $customer; but later when I access that session var [in the the same file but in a different function and different instance], php gives me an error saying: The script tried to execute a methode or access a property of an incomplete object. Pleas ensure that the class definition lt;bgt;customerlt;/bgt; of the object you are trying to operate on was loaded _before_ the session was started at filepath/acceptPayment.php line 103 I did a little reading (rtfm) on php.net and saw that if session.auto_start is turned on, you couldn't use Objects with sessions. Well I checked my ini and the session.auto_start was set to 0, so I am now scratching my head in confusion. I require_once the Customer class and start the session after the requires and includes, so then I thought ok require_once so I change it to require and then it doesn't load the class the for some reasone (sigh). Any Ideas? Thanks for your help in advance Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sessions and objects
Don't store your object in the session, that is just bad design. Store a lookup value, then grab your object from your DB only when you need it. Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: [EMAIL PROTECTED] http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "LINUX is obsolete" -- Andy Tanenbaum, January 29th, 1992 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://www.JEEP-FOR-SALE.com/ -- I need a buyer Get your own Free, Private email at http://www.smackdown.com/ On Thu, 22 Feb 2001, Kevin Beckford wrote: Date: Thu, 22 Feb 2001 12:36:29 -0500 From: Kevin Beckford [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [PHP] sessions and objects Hello all, I've been away from php for a while, ( and I'm glad to be back) Last time I checked in, sessioning was kinda working - especially the sessioning of objecs. Is this feature robust enough for production now? I want to do basic sessioning, and I don't have a lot of development time. What I want to do is simply : - Log in -instantsiate an object that will contain the user information -save the data in session -allow me to recreate that object from page to page How would I do/find out how to do this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] sessions and objects
Why is this good design? If I create a user object, populate it, kill the connection to the database (or return it to the pool) and cache the object then I can retrieve it any time I want without having to hit the database. Not arguing, just curious as to your perspective. Cal http://www.calevans.com -Original Message- From: jeremy brand [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 22, 2001 11:46 AM To: Kevin Beckford Cc: [EMAIL PROTECTED] Subject: Re: [PHP] sessions and objects Don't store your object in the session, that is just bad design. Store a lookup value, then grab your object from your DB only when you need it. Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: [EMAIL PROTECTED] http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "LINUX is obsolete" -- Andy Tanenbaum, January 29th, 1992 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://www.JEEP-FOR-SALE.com/ -- I need a buyer Get your own Free, Private email at http://www.smackdown.com/ On Thu, 22 Feb 2001, Kevin Beckford wrote: Date: Thu, 22 Feb 2001 12:36:29 -0500 From: Kevin Beckford [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: [PHP] sessions and objects Hello all, I've been away from php for a while, ( and I'm glad to be back) Last time I checked in, sessioning was kinda working - especially the sessioning of objecs. Is this feature robust enough for production now? I want to do basic sessioning, and I don't have a lot of development time. What I want to do is simply : - Log in -instantsiate an object that will contain the user information -save the data in session -allow me to recreate that object from page to page How would I do/find out how to do this? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Sessions and Objects
If I save an object as a session var. will I still have access to its methods. Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]