Welcome Guest, Not a member yet? Register   Sign In
Validate session to multiple views
#1

[eluser]Lokut Da[/eluser]
Hi! How have u been?

I have this controller:

test.php
Code:
$this->load->view('plantilla/head.tpl.php', $head);
$this->load->view('plantilla/left.tpl.php', $menu);
$this->load->view('logueo/index_logueo.php');

Well, I need to validate a session. If a determinate session exists, I must show or not a page.

This validation is for some pages no all (restricted pages). I want to have this validation in other file, but i don't know how must to do that on CI.

The idea is:

valida_sesion.php
Code:
if ( !$this->session->userdata('any') ) {
//if session "any" no exists, go to index page
redirect('index');
}

Then, can use that validation on controllers.

How must to do the validation for the pages i need?

I hope u can help me Confusedmirk:

Thanks!

PDT: Excuse my english!
#2

[eluser]InsiteFX[/eluser]
Maybe a MY_Controller? Codeigniter Users Guide.

InsiteFX
#3

[eluser]Lokut Da[/eluser]
I'm reading...

Do u know other way to do the same?

Thanks for ur answer... Smile
#4

[eluser]Lokut Da[/eluser]
Yea! thanks for ur answer, i could solve the problem Smile

I have created a library for that. The library is responsable of watch who have permissions to be on the private pages.

Code:
<?php
if(!defined('BASEPATH'))
    exit('No direct script access allowed');

class Valida_Sesion
{
    public function __construct()
    {
        $cI = get_instance();

        $cI->load->library('Session');

        if (!$cI->session->userdata('usuario')) {
            redirect();
        }
    }
}

So... it's ok! And one question Tongue I'm loading this library on global context:

autoload.php
Code:
$autoload['libraries'] = array('database', 'Valida_Sesion');

I need for index page NO load the Class Centinela, do u know how can do it?

Thanks in advance!




Theme © iAndrew 2016 - Forum software by © MyBB