Solved

incomplete class user error?

Posted on 2006-07-20
10
412 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
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 250 total points
ID: 17149164
$obj = unserialize($_SESSION['member']);
that is...
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17149171
ok brb...
0
Industry Leaders: 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!

 
LVL 9

Accepted Solution

by:
Rob_Jeffrey earned 250 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 250 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
reverse engineer .sql from php files 11 49
Simple function not working 7 43
Date comparison to same 'wednesday' of previous year 3 28
$_GET call between URL 3 37
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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 …

685 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