Welcome Guest, Not a member yet? Register   Sign In
Site built now session problem
#11

[eluser]the_unforgiven[/eluser]
So by adding this, will this change anything to my code already? Or will I have to re-write everything based around the MY_Controller?

Or would i just do

Code:
class Admin extends My_Controller {

// code here i already have
}
instead of extends CI_Controller?
#12

[eluser]CroNiX[/eluser]
You would just have to change it for each controller that needs the authentication (or anything else you decide to have MY_Controller do), like you showed above (except it is MY_Controller, not My_Controller.)

MY_Controller.php goes in
/application/core/MY_Controller.php

Code:
class MY_Controller extends CI_Controller
{
function __construct()
{
  parent::__construct();
                //your authentication code here...
}
}

All of you other controllers go in
/application/controllers
as normal, but the ones that need the auth now need to extend MY_Controller. Ones that don't just extend CI_Controller as normal.

http://ellislab.com/codeigniter/user-gui...asses.html
#13

[eluser]the_unforgiven[/eluser]
I tried this and everything everyone has said on this thread, but when i extend MY_Controller i cant access admin at all.
#14

[eluser]CroNiX[/eluser]
Hard to say without seeing all of your code. When done properly, it works great. I do it on all of my projects from the getgo. So you are not doing something correctly. It could be the order that you are loading things. I'd suggest loading your auth within MY_Controller if you aren't already (not in a controller that extends MY_Controller) - in addition to checking the user.
#15

[eluser]the_unforgiven[/eluser]
Ok ive posted all or most of the admin controller here -> http://pastie.org/5679761

All extends to MY_controller which is: - > http://pastie.org/5679771

So maybe you can point me in the right direction, please dont laugh at my code i know its not the best nor is it tidy but still in dev stage anyhow, last thing i do is clean it all up!
#16

[eluser]CroNiX[/eluser]
Do you have debugging and display errors turned on? What does "cannot access admin at all" mean? What messages do you see? What do the logs say? Where are these files located?
#17

[eluser]the_unforgiven[/eluser]
MY_Controller is located in application/core
admin.php is located application/controllers

And it says cannot locate controllers/admin.php
#18

[eluser]the_unforgiven[/eluser]
Just changed things slightly in MY_Controller
Code:
public function __construct()
{
  parent::__construct();
  if($this->session->userdata('is_admin') == false)
  {
   redirect('access/denied', 'refresh'); // Redirects to restricted page
  }
}
But then if i go to localhost/site/admin it just throws the redirect to restricted page!
#19

[eluser]CroNiX[/eluser]
Did you try doing a var dump of session::all_userdata() in that construct and see what shows up? Maybe with messing around you aren't actually logged in anymore.
#20

[eluser]the_unforgiven[/eluser]
The var dump provided the following:

Code:
array(11) { ["session_id"]=> string(32) "7ba7e2b866a5a04b676e6ba7a6d3f74a" ["ip_address"]=> string(3) "::1" ["user_agent"]=> string(81) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/20100101 Firefox/18.0" ["last_activity"]=> int(1358114539) ["user_data"]=> string(0) "" ["id"]=> string(1) "1" ["username"]=> string(5) "admin" ["name"]=> string(11) "Admin User" ["is_admin"]=> bool(true) ["is_logged_in"]=> bool(true) ["last_login"]=> int(1358113770) } ­

Which shows admin user currently logged in, so if I login to a customers account and navigate to the /admin/ panel i get

Code:
array(13) { ["session_id"]=> string(32) "cf74192bdabf638e9341b9e1bf3afbc3" ["ip_address"]=> string(3) "::1" ["user_agent"]=> string(81) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/20100101 Firefox/18.0" ["last_activity"]=> int(1358114787) ["user_data"]=> string(0) "" ["user_id"]=> string(1) "1" ["username"]=> string(8) "lstables" ["name"]=> string(3) "Customer" ["fullname"]=> string(11) "A Customer" ["status"]=> string(1) "1" ["is_user"]=> bool(true) ["is_logged_in"]=> bool(true) ["last_login"]=> int(1358114794) } ­

Which shows is a user, so would i just do another session data varible to say is_admin == false?




Theme © iAndrew 2016 - Forum software by © MyBB