?
Solved

incomplete class user error?

Posted on 2006-07-20
10
Medium Priority
?
416 Views
Last Modified: 2012-06-27
when a user logs in, i set some session vars and redirect them to a secure page.

I have been having a few problem tonight and i think i have foud the cause but dont know what it means..

if i print out the set session vars before redirecting the user is get the correct info, but when i print out the session vars again on the secure page to see if they are ok (just for debugging) they are different???

HOW I SET SESSION VARS

<?php
// other code here

$query = "SELECT * FROM tblMembers WHERE username = '".$s_Username."' AND password = '".md5($s_Password)."'";
$result = odbc_exec($link_id,$query);
$userData = odbc_fetch_object($result);

require('user.class.php');

session_start();

$_SESSION['member'] = new User($userData->username, <<< OTHER STUFF HERE>>> $userData->email);
$_SESSION['timestamp'] = time();

//header('Location: profile.php');
//exit;
            
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
exit;
?>

and its output:

Array
(
    [member] => user Object
        (
            [username] => null
            [firstname] => null
            [surname] => null
            [email] => null@null.com
        )

    [timestamp] => 1153424076
)

SECURE PAGE CODE:

<?php
session_start();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
exit;
?>

and its output:

Array
(
    [member] => __PHP_Incomplete_Class Object
        (
            [__PHP_Incomplete_Class_Name] => user
            [username] => null
            [firstname] => null
            [surname] => null
            [email] => null@null.com
        )

    [timestamp] => 1153424159
)

USER CLASS CODE

<?php
class User
{
      var $username;
      var $firstname;
      var $surname;
      var $email;
      
      function User($username, $firstname, $surname, $email)
      {
            $this->username = $username;
            $this->firstname = $firstname;
            $this->surname = $surname;
            $this->email = $email;
      }
}
?>

So as im not a PHP experts i dont know what this __PHP_Incomplete_Class Object means??

Any idea's?

Thanks Ellandrd
0
Comment
Question by:ellandrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 29

Assisted Solution

by:TeRReF
TeRReF earned 1000 total points
ID: 17149162
You have to serialize objects before storing them in a session.
Try this:
instead of:
$_SESSION['member'] = new User($userData->username, <<< OTHER STUFF HERE>>> $userData->email);

Do:
$_SESSION['member'] = serialize(new User($userData->username, <<< OTHER STUFF HERE>>> $userData->email));

The when retirving the object from session do:
$obj = unserialize($_SESSION['member'];
0
 
LVL 29

Assisted Solution

by:TeRReF
TeRReF earned 1000 total points
ID: 17149164
$obj = unserialize($_SESSION['member']);
that is...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17149171
ok brb...
0
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 1000 total points
ID: 17149177
On the secure page you need to include
require('user.class.php');

Before the Session_start().  The compiler does not know what to do with the stored class until it's defined.
0
 
LVL 9

Expert Comment

by:Rob_Jeffrey
ID: 17149189
- Right TeRReF is right...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17149216
after i do this:

$obj = unserialize($_SESSION['member']);

how do i retrieve the data stored in the sessiona again?

my code is:

<?php
session_start();

$obj = unserialize($_SESSION['member']);

if(isset($_COOKIE['autologin']) && !isset($obj))
{
}
else if(isset($_SESSION['member']))
{
}

but my session is blank....

e.g:

echo $_SESSION['member']->username; return blank
0
 
LVL 29

Assisted Solution

by:TeRReF
TeRReF earned 1000 total points
ID: 17149337
I assigned $_SESSION['member'] to $obj as an example...
If you really want it in $_SESSION['member'], just do this:
$_SESSION['member'] = unserialize($_SESSION['member']);
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17149341
To clarify things,
echo $obj->username;
would work...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17152544
Rob_Jeffrey

I now get:

Fatal error: Cannot redeclare class user in e:\domains\q\xxx\user\htdocs\classes\user.class.php on line 3

profile page code:

<?php
include('includes/config.php');
require('classes/user.class.php');

session_start();

if(isset($_COOKIE['autologin']) && !isset($_SESSION['member']))
{
      // register session using cookie detials etc etc
      header('Location: profile.php');
}
else if(isset($_SESSION['member']))
{
       // show user secure contents...
}
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17158064
Instead of this:
include('includes/config.php');
require('classes/user.class.php');

try this:
include_once('includes/config.php');
require_once('classes/user.class.php');
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question