473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Check if admin has logged in (CodeIgniter)

2
If there's someone logged in, this code checks the sessions and I can successfully view the page, but now I'd like to check if the user is admin. I've tried checking for this in the model and I keep getting a few errors. One of them is "Fatal error: Call to undefined function where() in C:\xampp\htdocs\ecwm604\application\models\usermod el.php on line 54"

Expand|Select|Wrap|Line Numbers
  1. public function index()
  2.     {
  3.         $this->load->library('authlib');
  4.         $loggedin = $this->authlib->is_loggedin();
  5.         ///$admin = $this->auth->admin();
  6.  
  7.         if ($loggedin === false) {
  8.                 $this->load->helper('url');
  9.                 redirect('/auth/login');
  10.          }
  11.                 if ($this->auth->admin() === false) {
  12.         $message ['msg'] = "You are not an admin!";
  13.         $this->load->view('homeview', $message);
  14.         }
  15.         else
  16.         {
  17.         $this->load->view('add_view');
  18.         }
  19.     }
  20.  
The line $this->admin($username,$password); passes to admin() below
Expand|Select|Wrap|Line Numbers
  1. --Controller Auth 
  2.  
  3.     public function authenticate()
  4.     {
  5.     $username = $this->input->post('uname');
  6.     $password = $this->input->post('pword');
  7.     $user = $this->authlib->login($username,$password);
  8.     >> $this->admin($username,$password); <<passes to admin()below
  9.     if ($user !== false) {
  10.         $this->load->view('homeview',array('name' => $user['name']));
  11.  
  12.     }
  13.     else {
  14.         $data['errmsg'] = 'Unable to login - please try again';
  15.         $this->load->view('login_view',$data);
  16.     }    
  17.     }
  18.  
  19.     public function admin($username,$password){
  20.     //$this->load-model('usermodel');
  21.     $admin = $this->authlib->adminlib($username,$password);
  22.     if ($admin == false){
  23.     return false;
  24.     //if ($res->num_rows() != 1){
  25.     //return false;
  26.     }
  27.     }
Expand|Select|Wrap|Line Numbers
  1. --Library Authlib 
  2.  
  3.     public function adminlib($user,$pwd) 
  4.     {
  5.     return $this->ci->usermodel->chkadmn($user,$pwd);
  6.     }
  7.  
Error is taking place on line 5 below:
Expand|Select|Wrap|Line Numbers
  1. --Model Usermodel 
  2.  
  3.     function chkadmn($username,$password)
  4.     {
  5. <<This is where the error is taking place>>$this->db-where(array('username' => $username,'password' => sha1($password)));
  6.     $res = $this->db->get('users',array('type'));
  7.     if ($res->num_rows() != 1) {
  8.     return false;
  9.     }
  10.     }
Dec 31 '12 #1
3 6360
zmbd
5,501 Expert Mod 4TB
ethio:

Merely posting the code and giving a generic, paraphrased, error message and the "this doesn't work" is not enough to help you. Bytes is not a code writing nor homework service. Please read the FAQ and posting guidlines. I hate to just outright delete the post as you've taken the time to include your code.

However:

We must insist that you take the time to do the basic trouble shooting on your own system first in that we do not have the same PC, programs, nor access to your data.

As for errors, you must provide the EXACT title, error number, and error description along with at what point in your code the error occurs - without this basic information, it's is difficult at best to offer any help.

So, without some basic effort and information on your part, even if someone manages to offer you some guidance, your thread may be subject to deletion.
Dec 31 '12 #2
ethio
2
I have taken the time to do basic trouble shooting on my own system. In fact, I've been trying to fix this since yesterday night. But I have added the exact error message and it happens in the usermodel $this->db->where(...
Dec 31 '12 #3
acoder
16,027 Expert Mod 8TB
I've added some comments to your post (taken from your code) which should help explain the problem better (it's easy to miss in all the lines of code).

I don't use CodeIgniter, but is there not a better method to check for admin, e.g. roles?

As for your error, is $this->db-where a typo or did you miss the > character, i.e. it should be $this->db->where?
Dec 31 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gaurav | last post by:
Hi, is there a way to know which user last logged in the shared Access database. My requirement is that I must be able to track the users that log in the database and incase its not working...
2
by: Joe Saliba | last post by:
hi, hope somebody could help me with this, have some users created on an sql 2000, and am trying to know which user opened the adp , so everytime i put msgobx currentuser it gives me admin, though...
3
by: Alan Silver | last post by:
Hello, I have some pages that are protected by forms authentication, and am adding code to the global.asax so that if someone tries to load (say) /order83.aspx, if they are logged in, it will...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
1
by: pagates | last post by:
Hi All, This must be a simple question, but I just can't figure it out. I want to know if the user is logged in programmatically. I tried to use the LoginStatus control, but of course that...
4
by: Dan Holmes | last post by:
I admit this not being C# specific but i don't know where else to start. My application needs an "administrator" user id. This would function just like the "administrator" user id in windows. ...
0
by: surfivor | last post by:
I am doing some preliminary research as we are slated to do a project with wordpress. I looked at the wordpress code and realized why I like MVC so much (Rails) because the code mixed in with the...
3
TheServant
by: TheServant | last post by:
Can anyone tell me why flashdata is not immediately available? Is it only available once the page has been resent? I am using form validation for form fields and flashdata for error messages. If...
7
dlite922
by: dlite922 | last post by:
Hey guys, I can't find a good snippet to check whether an php error has occurred (maybe warning and notices too). I'm doing this for codeIgniter. I'm trying to prevent my template/view from...
2
vivekgs2007
by: vivekgs2007 | last post by:
hi to all, I am using the php from last 1 year…this is my first framework i am using i downloaded CodeIgniter and made the configaration as listed above..i am also using wamp server.. I am getting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.