Solved

incomplete class user error?

Posted on 2006-07-20
10
405 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
  • 5
  • 3
  • 2
10 Comments
 
LVL 29

Assisted Solution

by:TeRReF
TeRReF earned 250 total points
Comment Utility
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 250 total points
Comment Utility
$obj = unserialize($_SESSION['member']);
that is...
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
ok brb...
0
 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 250 total points
Comment Utility
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
Comment Utility
- Right TeRReF is right...
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Author Comment

by:ellandrd
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
To clarify things,
echo $obj->username;
would work...
0
 
LVL 16

Author Comment

by:ellandrd
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now