![]() |
Redirect from Libraries - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Redirect from Libraries (/showthread.php?tid=72129) |
Redirect from Libraries - smrutigml - 11-09-2018 <?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 RE: Redirect from Libraries - php_rocs - 11-09-2018 @[email protected] How is your base_url configured? Also, have you tried a different page to see it that works? RE: Redirect from Libraries - dave friend - 11-09-2018 (11-09-2018, 05:57 AM)[email protected] Wrote: <?php 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 RE: Redirect from Libraries - InsiteFX - 11-10-2018 Try that: PHP Code: redirect('/'); RE: Redirect from Libraries - dave friend - 11-10-2018 (11-10-2018, 05:50 AM)InsiteFX Wrote: Try that: Or simply PHP Code: redirect(); RE: Redirect from Libraries - mawanboyz - 03-10-2020 redirect it's work but not refreshed to that page RE: Redirect from Libraries - InsiteFX - 03-11-2020 Check and see if your web page is being cached. |