Welcome Guest, Not a member yet? Register   Sign In
Sessions - Bug?
#21

[eluser]The Wizard[/eluser]
i really dont know,
all i know, i had the same problem,
i fixed it somehow, i remember that the
path was crucial, like majidmx sayed.

lets ask dr house Smile
#22

[eluser]majidmx[/eluser]
I remember in one of the projects setting the cookie domain helped me a lot in terms of getting sessions working properly.

so set it like this :
Code:
$config['cookie_domain']    = ".yahoo.com";
if you want to make the cookies available site wide.

and if you make it either of these cases :
Code:
$config['cookie_domain']    = "www.yahoo.com";
    or
$config['cookie_domain']    = "subdomain.yahoo.com";
it will be only available when user is those specific sub-domain. So to be on the safe side it's better to use the site wide one. [it depends on what your project implies]

We just want to figure out the root of the problem, so we won't face it anymore, as your problem is fixed right now.

btw, is there any benefit in not closing the PHP files with "?>" ? I close the scripts all the time, what's the difference ?
#23

[eluser]The Wizard[/eluser]
majidmx: yes there is ! http://ellislab.com/codeigniter/user-gui...guide.html Smile

for the session bug, i encountered it again, now im trying to figure out, where it is, and im going crazy.
#24

[eluser]The Wizard[/eluser]
i think i got it, let me post you a unit and its failure.
Code:
<?php

class Model_session extends Model
{

    function Model_session()
    {
        parent::Model();

        $this->load->library('session');
    }

    function Session_Create( $data )
    {
        $this->load->library('session');

        $data_session['user_id']        = $data['user_id'];
        $data_session['cloak_id']       = $data['cloak_id'];

        $data_session['user_name']      = $data['user_name'];
        $data_session['user_email']     = $data['user_email'];

        $data_session['logged_in']      = TRUE;

//        echo '<pre>';
//        print_r( $data );
//        echo '</pre>';
//        die('');

        $this->session->set_userdata( $data );
    }

    function Session_Destroy ()
    {
        $this->load->library('session');
        $this->session->sess_destroy();
    }

    function Session_Check ( $return_link = FALSE )
    {
        $this->load->library('session');

        $auth        = $this->session->userdata('logged_in');  // BUG <--- THIS IS THE BUG
        if ( $auth == FALSE )
        {
            if ( $return_link == TRUE )
            {
                $return_value = anchor( 'http://www.kivvix.org/user/login', 'Login Here' );
            }
            else
            {
                $return_value = FALSE;
            }

        }
        elseif ( $auth == TRUE )
        {
            if ( $return_link == TRUE )
            {
                $user_name = $this->session->userdata['user_name'];
                $return_value = anchor( 'http://www.kivvix.org/user/' . $user_name, $user_name );
            }
            else
            {
                $return_value = TRUE;
            }
        }

        return $return_value;

//        $session_id        = $this->session->userdata('user_id');
//
//        if ( $session_id <= 0 )
//        {
//            return FALSE;
//        }
//        else
//        {
//            return TRUE;
//        }
    }

    function Session_UserID ()
    {
        $this->load->library('session');
        $user_id = $this->session->userdata('user_id');

        if ( $user_id == '' )
        {
            $user_id = 0;
        }

        return $user_id;
    }

    function Session_CloakID ()
    {
        $this->load->library('session');
        $user_id = $this->session->userdata('cloak_id');

        if ( $user_id == '' )
        {
            $user_id = 0;
        }

        return $user_id;
    }

    function Session_Username ()
    {
        $this->load->library('session');
        $user_name = $this->session->userdata('user_name');

        if ( $user_name == '' )
        {
            $user_name = FALSE;
        }

        return $user_name;
    }



    function Session_Email ()
    {
        $email = $this->session->userdata('email');

        if ( $email == '' )
        {
            $email = -1;
        }

        return $email;
    }

    function Session_ThemeID ()
    {
        $theme_id = $this->session->userdata('themeid');

        if ( $theme_id == '' )
        {
            $theme_id = 0;
        }

        return $theme_id;
    }

}


?&gt;

so, if you check when the session is created, it gets a BOOLEAN value,
TRUE. So when you compare a BOOL, it somehow returns FALSE even if its there.

for me, THIS was the bug and im PRETTY SURE, people have this too Smile

THERE ARE some STRANGE BEHAVOURS in CI SOMETIMES, that you should be aware off.

Im off to duty, take care friends Wink




Theme © iAndrew 2016 - Forum software by © MyBB