Welcome Guest, Not a member yet? Register   Sign In
Firs time with sessions
#1

[eluser]alebenson[/eluser]
hi there!

i've made this to try doing an admin area, and play with the session library...
but when i try $this->session->sess_destroy(''); i get an error

any ideas?

Code:
class Admin extends Controller {
    
function index()
{
    $this->load->helper('url');
    
    $this->load->library('validation');
        $rules['usuario'] = "required";
        $rules['password'] = "required";
        
        $fields['usuario'] = 'Usuario';
    $this->validation->set_rules($rules);
    $this->validation->set_fields($fields);
/*-------------------------------------------------------------*/
    $usuario = $this->input->post('usuario');
    $password = $this->input->post('password');
    if ($this->validation->run() == TRUE)
    {
        if ($usuario == 'admin' and $password == 'ppp'){
            $this->load->library('session');
            
            echo $data = $this->session->userdata('session_id').'<br>';
            echo $data = $this->session->userdata('ip_address').'<br>';                
            echo $data = $this->session->userdata('user_agent').'<br>';
            echo $data = $this->session->userdata('last_activity').'<br>';
            echo $data = $this->session->userdata('last_visit').'<br>';
            
        }
        else if ($usuario == 'noadmin' and $password == 'xxx') {
            $this->session->sess_destroy('');            
        }
        else
        {
            echo 'fuck fuck fuck';
        }
    }
    else
    {
        $data = array('error' => ' ');
        $this->load->view('admin_view.php', $data);
    }
}
}
#2

[eluser]Michael Wales[/eluser]
What is the error?
#3

[eluser]alebenson[/eluser]
Fatal error: Call to a member function on a non-object in /home/zbale/public_html/ci/system/application/controllers/admin.php on line 38

line 38 is $this->session->sess_destroy('');
#4

[eluser]LuckyFella73[/eluser]
Your controller is loading the session-library only
if user="admin" and password="ppp", so if your contoller
get to the "else" part, the object/ function of the session library
is not present and not accessable.
Try to load the session-library at the beginning of the method.
#5

[eluser]alebenson[/eluser]
thanks!! well that works fine...

but i dont get something...
that whould enable the session without asking for the pass... that dont make sense

or the idea is to enable the session library always and passit a user flag and always check for that flag ?
#6

[eluser]dawnerd[/eluser]
[quote author="alebenson" date="1200874677"]thanks!! well that works fine...

but i dont get something...
that whould enable the session without asking for the pass... that dont make sense

or the idea is to enable the session library always and passit a user flag and always check for that flag ?[/quote]

You're not enabling the session. You're just loading the session class which gives you access to all the methods inside it, such as sess_destroy().

It's actually best to autoload the session class since it's used quite often.

I also might add that the db_session library is a lot more secure than the regular session class.
#7

[eluser]alebenson[/eluser]
i get that... ok ill try it

thanks thanks thanks




Theme © iAndrew 2016 - Forum software by © MyBB