Welcome Guest, Not a member yet? Register   Sign In
Redirect from Libraries
#1

<?php  
if (!defined('BASEPATH')) die('No direct script access allowed');
class UserInfo {

var $CI;
var $userId;
var $userDisplayName;
var $userEmail;
var $userThumb;

public function __construct($params = array())
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');
        $this->CI->config->item('base_url');
        $this->CI->load->database();  //Optional if any database interaction needed
        $this->getUser();
    }

public function getUser(){

if(empty($this->CI->session->userdata('sessionUid'))){
    redirect(base_url());
}else{
    $this->userId = $this->CI->session->userdata('sessionUid');
    $this->userEmail = $this->CI->session->userdata('sessionMail');
    $this->userDisplayName = $this->CI->session->userdata('sessionDname');
    $this->userThumb = $this->CI->session->userdata('sessionThumb');
}

}

}
?>


Above is my Code where i have created a new Library Class "UserInfo" and auto loading this library in autoload.php

$autoload['libraries'] = array('ActiveRecord','database','session','UserInfo');

However when a session is not exist(here i am checking the session "sessionUid") it should take me to the baseurl but it is throwing
500 error. 
if i am commenting that redirect script the page is loading fine.

Any help will  be highly appreciated.


Thanks
Smrutikant
Reply
#2

@[email protected]

How is your base_url configured? Also, have you tried a different page to see it that works?
Reply
#3

(11-09-2018, 05:57 AM)[email protected] Wrote: <?php  
if (!defined('BASEPATH')) die('No direct script access allowed');
class UserInfo {

var $CI;
var $userId;
var $userDisplayName;
var $userEmail;
var $userThumb;

public function __construct($params = array())
    {
        $this->CI =& get_instance();
        $this->CI->load->helper('url');
        $this->CI->config->item('base_url');
        $this->CI->load->database();  //Optional if any database interaction needed
        $this->getUser();
    }

public function getUser(){

if(empty($this->CI->session->userdata('sessionUid'))){
    redirect(base_url());
}else{
    $this->userId = $this->CI->session->userdata('sessionUid');
    $this->userEmail = $this->CI->session->userdata('sessionMail');
    $this->userDisplayName = $this->CI->session->userdata('sessionDname');
    $this->userThumb = $this->CI->session->userdata('sessionThumb');
}

}

}
?>


Above is my Code where i have created a new Library Class "UserInfo" and auto loading this library in autoload.php

$autoload['libraries'] = array('ActiveRecord','database','session','UserInfo');

However when a session is not exist(here i am checking the session "sessionUid") it should take me to the baseurl but it is throwing
500 error. 
if i am commenting that redirect script the page is loading fine.

Any help will  be highly appreciated.


Thanks
Smrutikant

Using base_url() as an argument redirect() is not necessasary e.g. redirect(base_url());
redirect() figures out what base_url is by itself and will incorporate it into the new location URL
Reply
#4

Try that:

PHP Code:
redirect('/'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(11-10-2018, 05:50 AM)InsiteFX Wrote: Try that:

PHP Code:
redirect('/'); 

Or simply

PHP Code:
redirect(); 
Reply
#6

redirect it's work but not refreshed to that page
Reply
#7

Check and see if your web page is being cached.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB