Hooks doesn't works on private hosting - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Hooks doesn't works on private hosting (/showthread.php?tid=59981) Pages:
1
2
|
Hooks doesn't works on private hosting - El Forum - 12-22-2013 [eluser]viher[/eluser] Hello everyone, I have an application made with CodeIgniter 2, this app works perfectly in my localhost, but when i have uploaded it into my private server (production server), i have the following errors: Quote:A PHP Error was encountered So i thought my problems come from the check login hook. The hook code: app/config/hooks.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); app/hooks/user_control_hook.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Which could be the problem? Thank you! Hooks doesn't works on private hosting - El Forum - 12-22-2013 [eluser]Tpojka[/eluser] Seems that problem starts in home controller? Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]viher[/eluser] [quote author="Tpojka" date="1387755937"]Seems that problem starts in home controller?[/quote] controllers/home.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); The get_user_groups() method in libraries/User_control.php is a simple query to database: Code: /* Like i said in first post, this works fine on my localhost, and i have the same class construct in other application controllers. Thank you! Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]Karman de Lange[/eluser] You referencing a Array element that does not exist (row 15) Make sure by using the profiller that you actually have session data or do Code: var_dump($this->session->userdata("user_data") It could be that your login system don't work properly on production (perms issue, cookies conflicts etc) and your session data returns null which then means your $this->user won't have any elemnts L: Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]Tpojka[/eluser] Also,([I don't know if matter this time, but]) you should name your controller with capital letter. Code: class Home extends CI_Controller { Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]viher[/eluser] I tried what you said, but i have find where is the problem, but not the solution. Like i said on first post, the problem is in the Hook. Why?. Because when you enter in the website, the Hook is executed before controller is loaded, then if the user is logged (checks the user session data) the system redirects you to the main page, if not, the system redirects you to the login page. But in production server, if you are not logged, the system prints the error that i wrote in the first message and he doesn't redirects you to the login page. If you access to the login page directly, the system works fine: Now when you are logged and you access to the main page, the hook redirects you correctly. What can i do? Thank you so much! Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]Tpojka[/eluser] Declare Code: private $ci; class user_control_hook. // just thinking loud Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]Karman de Lange[/eluser] Can you try following: Change : Code: $this->user_groups = $this->user_control->get_user_groups($this->user['ID']); Code: $this->user_groups = isset($this->user['ID']) ? $this->user_control->get_user_groups($this->user['ID']):null ; Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]viher[/eluser] [quote author="Karman de Lange" date="1387802311"]Can you try following: Change : Code: $this->user_groups = $this->user_control->get_user_groups($this->user['ID']); Code: $this->user_groups = isset($this->user['ID']) ? $this->user_control->get_user_groups($this->user['ID']):null ; Wow! With this change it works fine! Thank you so much! And Tpojka too! Hooks doesn't works on private hosting - El Forum - 12-23-2013 [eluser]Karman de Lange[/eluser] Yup, Welcome to errors and php ;-) What happening is (my understanding of it): My redirect sets the browser headers with a 301, but now you getting a php error that also trying to set errors (error 500 or something) so you end up with headers already set error (Might be happening the other way around). So what the line now does is : Check if the user array have the element "id" , if so, then get the groups, otherwise just assign null to the $this->user_groups. L: |