Welcome Guest, Not a member yet? Register   Sign In
Redirect, but how stay in actuall page?
#1

[eluser]Martin_new[/eluser]
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('is_login'))
{
    function is_login()
    {
        $CI =& get_instance();

        $logged_in = $CI->session->userdata('logged_in');

        if (!isset($logged_in) || $logged_in != TRUE) {
            redirect('login');

        }  
    HERE
    }  
}

I have this code. And I want check if user is logged in, everything is ok, re redirect is gooood. But in "HERE" I want to stay in actuall page, no refresh or redirect. How can I do it?

And another question. How can I check if the user is logged in, in every page?
#2

[eluser]Juan Velandia[/eluser]
what about the url helper’s current_url()?
#3

[eluser]Martin_new[/eluser]
It`s not good solution. When I use
Code:
current_url()
function, I have double link http://localhost/index.php/check_login/l.../logged_in, and I want to stay in current page in every case and function current_url() take url from actuall controller who call this function, but I want to stay in page who called this function.
#4

[eluser]gmcms[/eluser]
Quote:And another question. How can I check if the user is logged in, in every page?
You can use a hook to check for user logged in on every controller call or extends CI_Controller.
Regards
#5

[eluser]Barwick[/eluser]
[quote author="Martin_new" date="1351543748"]
And another question. How can I check if the user is logged in, in every page? [/quote]

Just store "logged_in" session in your model and check for it on every controller you need it to. Have it validate and then run your methods, etc. For example:

Code:
public function index()
    {            
        $user = $this->session->userdata('logged_in');        
        
        if ($user == 1) // if logged in
        {
           run this
        }
        else // if not logged in
        {
           run this                                      
        }          
    }
#6

[eluser]Juan Velandia[/eluser]
post your code, Its really strange you get a doble URL...




Theme © iAndrew 2016 - Forum software by © MyBB