Solved

incomplete class user error?

Posted on 2006-07-20
10
408 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

777 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