[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

incomplete class user error?

Posted on 2006-07-20
10
Medium Priority
?
422 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 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