Web Analytics Made Easy -
StatCounter Too good to be true - CodingForum

Announcement

Collapse
No announcement yet.

Too good to be true

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Too good to be true

    I tried recently to insert an class object as a session var,
    not realy sure about the result.

    1. It works
    2. It doesn't save the methods, just the object vars
    3. all you have to do is include the class before starting the session


    PHP Code:
    <?
    include('class_user.php');

    session_start();

    if(!isset(
    $_SESSION['user'])){
    $_SESSION['user'] = new User;
    }

    $user = &$_SESSION['user'];

    ... 
    your page ....

    ?>
    As this sounds too easy, I was wondering where's the trick.
    Does anyone know a downside to this ?
    Last edited by Yusogga; Mar 10, 2004, 10:42 AM.

  • #2
    You need to read our posting guidelines section 2 before creating anymore threads.
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      Shouldn't you write the session_start() first and then do whatever you wana do? Yes, I think you should do that! So, replace the 1st and 2nd line, and it's not even a trick!

      Comment


      • #4
        Originally posted by Spookster
        You need to read our posting guidelines section 2 before creating anymore threads.
        Spookster I acknowledged it, and I'm going to pay more attention to the formatting

        Shouldn't you write the session_start() first and then do whatever you wana do? Yes, I think you should do that! So, replace the 1st and 2nd line, and it's not even a trick!
        Actually no. Since the methods of a class are not kept into the sessions, you need to redefine them before entering session_start()!

        The code up there works fine, I added the formatting.
        Last edited by Yusogga; Mar 10, 2004, 10:42 AM.

        Comment

        Working...
        X