[dfads params=’groups=-1′]
Today, I came up with a solution for how to make an inbuilt Admin Panel with already coded Login module in codeigniter. Just follow the steps below to setup into your project.
1. Download the adminPanelWithLogin.zip file. Extract it. Copy the respective admin folders to the Controllers, Models, & Views of your project.
2. Create the MySQL table & populate data.
[sql]
CREATE TABLE IF NOT EXISTS `tbl_admin` (
`admin_id` int(4) NOT NULL AUTO_INCREMENT,
`admin_name` varchar(128) NOT NULL,
`admin_email` varchar(64) NOT NULL,
`admin_password` varchar(64) NOT NULL,
`admin_role` int(2) NOT NULL,
`admin_status` int(1) NOT NULL,
PRIMARY KEY (`admin_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;
INSERT INTO `tbl_admin` (`admin_id`, `admin_name`, `admin_email`, `admin_password`, `admin_role`, `admin_status`) VALUES
(1, ‘admin’, ‘admin’, ‘admin_123’, 1, 0),
(13, ‘super’, ‘super’, ‘super_123’, 1, 1);
[/sql]
3. Check whether the database & session are initiated by exploring to application/config/autoload.php file.
[php]$autoload[‘libraries’] = array(‘database’, ‘session’); [/php]
4. Browse the admin login from you browser: http://localhost/your_project/admin. A screen must appear like this:
5. Use the default admin user as “admin ” and Password as “admin_123” then press Login. You will be redirected to a secure home page like this:
You can further add modules of your choice & code your project as you like.
Feedbacks & suggestions are always welcome.
[dfads params=’groups=-1′]
Hey
I try all your instructions but when i try admin page it give me error that page not find. So any further instruction for this. Thanks
Deaer Adi, You might have been missing the clean URL part. So, please try this link to access the admin page: http://localhost/your_project/index.php/admin.
Hope this may work.
Regards
Admin
Will this work with a HMVC approach?
Dear Paul, This is done for plain CI. You can further modify the code according to your needs.
i am beginner in ci , i am facing similar problem, i have tried http://localhost/your_project/index.php/admin. also but there is no change….it would be very helpful for your further guidance
where is the MY_Controller file? refers to “class Home extends MY_Controller”
Dear arnezt,
Pleae rename MY_Controller to CI_Controller, that will work.
Thanx,
Admin
Thank you very much! I created that.
And due to your example I increase my knowledge in mvc.
I’m trying using your script and its goes page not found..i’ve tried http://localhost/app/index.php/admin
page not found
Dear Syafiq, something might have gone wrong with your code. Please recheck.
plz make sure u’ve managed ur .httaccess file or route.php file inside config/ folder.
same problem i’v faced but .htaccess worked for me…..
if u dnt have .htacces file plz google once and create a .httaccess file
thank you for share.. This really helped me
I try to use the latest version is not successful ci, ci weve uses the version number?
beg in reply to this comment ?
I am not sure about the latest version of the CI. We use earlier versions. But I hope there might not be any kind of issues with the latest version. Please visit http://ellislab.com/codeigniter for further information.
excellent information hope to get more in future.
i try to go to index.php/admin page but i redirect to index of my page and noting show to me.
so what can i do????
Did you put the files at correct location?
do you know the exact solution of this .httaccess in codeigniter because i test on wamp , i enable all of modules also add code in htaccess but its not working still, any suggestions you have.
Did u put the script as below in your .htaccess file?
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* your_project_name/index.php/$1 [PT,L]
The download link displays 404 error. The page cant be found. Kindly mail me the adminPanelWithLogin.zip file. Thanks in anticipation.
Dear Tunde,
You can Download the file from the same link.
Thanx.
Hello sir,
I have extracted the files as per you said.
I put different files as following
controller/admin
view/admin
models/admin
When I run using as this path : http://localhost/prahladandhari/avangatecms/admin
I get following errors :
Object not found. suggest solution.
Thanks.
Dear Parmar
You can try this link: http://localhost/prahladandhari/avangatecms/index.php/admin/login
I hope this works.
Thanks and sorry for late reply.
In order to use the Session class you are required to set an encryption key in your config file.
Yes Val, Its for your convinience. Its a better option if you use an encryption key.
error with style, exactly in VIEWBASE
that in view files.
how i can define it and where?
VIEWBASE is defined in /application/config/config.php
Enjoy coding.
Thanx,
Admin
Class ‘MY_Model’ not found in your download folder
Dear FR,
Make MY_Model to CI_Model, this will definitely work.
Thanks,
how can define VIEWBASE in config ??
$config[‘VIEWBASE’]=”http://localhost/example/” is it correct??
1. Locate the file config.php in /application/config/ directory
2. define(‘VIEWBASE’,’http://localhost/example/application/views/’); in that file.
Thanx
Dev
Respected sir when i try to access admin/index page through this url http://localhost/codeigniter/admin.
But there is showing welcome page and if i want to get http://localhost/codeigniter/index.php/admin still there is showing same welcome page.
Howdy, i read your blog from time to time and i own a similar one and i was just curious
if you get a lot of spam comments? If so how do you protect against it, any plugin or anything you can recommend?
I get so much lately it’s driving me crazy so any support is very much appreciated.
this is happened when login
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: admin/home.php
Line Number: 13
plz help to solve this issue i am tryin but not getting proper way..
David,
You have to define the value of your $data, then pass it like this: $this->viewForm($data);
David you can define your data value using
$data = “”;
if($this->session->userdata(‘xxxxxxxxx’)){
$query = $this->session->all_userdata();
$data[‘yyy’] = $query[‘xxxxx’];
$data[‘yyy’] = $query[‘xxxxx’];
$data[‘yyy’] = $query[‘xxxxx’];
}
$this->viewForm($data);
Please replace the xxx and yyy with name define in your code. It works for me.
dear sir,
i extract your files and replace the all folder like controllers with your folder controllers and same as views and models , after that i run the change the routes file with the default controllers index , but this is giving the error with “The page was you requested was not found “please help me with all steps .
you can try http://localhost/project_name/index.php/admin in the browsers URL.
Thanks
Admin
what is code i can write for admin path and front end path in to the routs.php?
Hi, i have succeed to run this trial apps, but the style won’t show eventhough i have defined the ‘viewbase’ code in config file. And i try to change the url src to be my link project refer to the css file something like this ‘http://localhost/project_name/application/views/admin/css/bootstrap.css’ but it still won’t show the style from the css files.
Maybe you can kindly tell me what’s wrong with this?
Thank you
Did u check whether you can access this url http://localhost/project_name/application/views/admin/css/bootstrap.css from the browser? You might have Access Forbidden problem. If yes, check the permission of the directories.
Thanks
Hello,
I downloaded the files and placed them on the specified locations. I used the RewriteRule provided by you earlier in this topic. I used “$route[‘admin/(:any)’] = “admin/$1″;” in routes.php, but still when I try to open the admin it gives me 404 error. Please let me know where I am lacking…?
Thanks
Hi,
I cracked my last step. But now I stuck in next hurdle. When I input the login credentials (admin, admin_123) in Login Area.
When I hit the login Button it remains on the same Login Window Page with redirected url in the bar to “admin/home” and it gives me the error msg: “Invalid username and/or password”.
I would req. you to provide the solution ASAP.
Thanks
Dear Mayank,
Please check whether you have created your mysql table / database. If yes, please check whether you are entering the right credentials.
Thanks
Dear Admin,
What should I do to get it done, login part. I just followed the same code provided by you.
Thanks
Hi Dev,
Thank you for the reply. I have created the database and credentials are correct. I used the same code provided above to create the database table. Do I need to create a session table…?
Thanks
Dear Mayank,
There is no need to create any session table.
Thanks
Dev
Dear Admin,
What should I do to get it done, login part. I just followed the same code provided by you.
Thanks
Dear Mayank,
Did you tried http://localhost/your_project/index.php/admin? If this is working you have to configure clean URL on your server.
Thanks
Dev
Dear Admin,
Yes I am working the same url pattern and yes it’s working, It is showing the login screens, but the problem occurs when I hit the login button.
Thanks
Dear Admin,
Please suggest the solution to my above mentioned query.
public function process(){
// Load the model
//$this->load->model(‘login_model’);
$this->load->model(‘admin/admin_model’);
// Validate the user can login
$result = $this->admin_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$msg = ‘Invalid username and/or password.’;
$this->index($msg);
}else{
echo “Loading…”;
// If user did validate,
// Send them to members area
redirect(base_url().’index.php/admin/home/’);
}
}
Both the conditions (If, else) are working from this code. I am using user as “admin ” and Password as “admin_123″
Please check what $result is printing using print_r. I am not sure what mistake you are making at your code. You can debug the code instead. You are very near to your goal.
Thanks
Dev
I tried using Print_r. Validation process is working fine. However I haven’t changed the code it’s same as I downloaded from here.
Here both If and else condition is working like when I input user as “admin ” and Password as “admin_123″, it redirects to home in URL but it remains on the same page (login), as well it prints the message “Invalid username and/or password”.
Thanks
There is a redirect() function in the controller home.php. This function is missing at your side. Please replace it with any redirect code.
Thanks
Dev
controller home.php
check_isvalidated();
}
public function index()
{
$this->viewForm($data);
}
private function check_isvalidated(){
if(! $this->session->userdata(‘validated’)){
redirect(‘admin/login’);
}
}
private function viewForm($data=”){
$this->load->view(‘admin/header’);
$this->load->view(‘admin/sidebar’);
$this->load->view(‘admin/home’, $data);
$this->load->view(‘admin/footer’);
}
}
?>
where should i use the redirect function. I tried it at different locations but didn’t get the success.
In my last post I provided the code of process() here I am not getting it how both the conditions are working.
Please send me the result after print_r($result).
Thanks
It shows 1 when I use user as “admin ” and Password as “admin_123″ and blank if I input wrong credentials.
I am using below mentioned routes, please let me know if I can do something here
$route[‘admin’] = ‘admin/login’;
$route[‘admin/(:any)’] = ‘admin/home/$1’;
$route[‘admin/(:any)’] = ‘admin/login/process’;
I have used the following routes in my routes.php
$route[‘default_controller’] = “home”;
$route[‘404_override’] = ”;
Thanks
Dev
If I use this route
$route[‘default_controller’] = “home”;
$route[‘404_override’] = ”;
It shows “404 Page Not Found”.
But when I use
$route[‘default_controller’] = ‘admin/home’;
$route[‘404_override’] = ”;
Its shows the home directly without login page, with the following error.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: admin/home.php
Line Number: 13
Thanks
I am using $route[‘default_controller’] for frontend as well. Below is the route.php code which I am using for frontend and admin part.
$route[‘admin’] = ‘admin/login’;
$route[‘admin/(:any)’] = ‘admin/home/$1’;
$route[‘admin/(:any)’] = ‘admin/login/process’;
$route[‘news/create’] = ‘news/create’;
$route[‘news/(:any)’] = ‘news/view/$1’;
$route[‘news’] = ‘news’;
$route[‘default_controller’] = ‘pages/view’;
$route[‘(:any)’] = ‘pages/view/$1’;
Thanks
Dear Admin,
Any solution of my query…?
Thanks
i have a suggestion for the developer to save support time for you what you dont offer the admin app for download already installed in a working codeigniter demo site plus the sql file and thats it.
thanks.
hi admin..
i'm gettnig error in VIEWBASE. and home page it showing list footer and all in center of page it showing empty box. how to solve it??
thank you.!
Dear Satish,
Sorry for late reply. Can you please send a screenshot of the output at nomeasdev@gmail.com? This will help me understanding your issue more clearly.
Thanks
i am a codeigniter beginner so what is the database name
i am getting error viewbase how ca solve this
Your method of describing everything in this piece of writing is actually nice, every one
can effortlessly understand it, Thanks a lot.
Oh my goodness! Incredible article dude! Thanks,
However I am experiencing troubles with your RSS.
I don’t know the reason why I cannot join it. Is there anyone
else getting the same RSS issues? Anybody who knows the solution will you kindly respond?
Thanks!!
I got this web site from my pal who shared with me on the topic of this web page and now this time I am visiting this web page and reading very
informative posts here.
Please help me downloading the files or mail me the files. Not able to download it from the given link.
Thankyou.
Please send the zip file by mail. Not able to download file.
Thanx in advance.
Hello, I am using your admin login on mysite,Everything is okay but I am unable to login using this code.I think session is not working .When I comment this section $this->check_isvalidated(); ,It’s login otherwise its not working.Please help me to fix this issues.
Thank you a lot for sharing this with all folks you actually understand
what you are talking approximately! Bookmarked.
Kindly additionally visit my site =). We could have a hyperlink alternate contract between us