Sunday, December 17, 2017

Today I will teach you how to create user login using codeigniter ,Let’s create login controller as below.
With this login we can create a function called as user_login(); that will load our login view. keep in mind, for good programming behavior, we will also include our constructor function, with in that call the parent constructor as well.

Once we created our login controller, we can go to the front and create our login view file. Here
we will create a very easy form, using some css styles to look superior. if needed, you can add this view file directly to your project.

If you observe above, the form action is set to – user_login. This is supercilious that your base_url is set as the following: “http://localhost/demos”. Notice the final slash.
So now, when we submit the login details it will navigate to user_login method. Within this method, we will call our model, and procedure our logic in the model. Let’s do so:

Now in the model we will create a method called validate. In this method we will query our database and get the user details and will return true or false, depending on the outcome. Also, we will use the codeigniter sessions class, to create a user-specific session. Now let’s check the method once.
If the confirmation was unsuccessful, then we need to inform the user that something is wrong.
Let’s add in a message representing the user to enter the valid username and password.
Using codeigniter session flash data we will create a message. Now we will add a parameter to our function in login controller. The evasion message will be null, sense there will be nothing to display, but if error occurs, we call the method with a message
Thanks for reading this article..
Live Demo

I am Saritha Reddy, a Remote codeigniter,Angularjs Developer. I have 4+ years of strong experience in designing, implementing, Programming and delivering advanced XAMPP ( Apache, MySQL and PHP) Web applications development. I am an Indian national and based Andhra Pradesh,Hyderabad. In addition to providing custom programming and design, I also have extensive experience with Open Source technologies to keep costs down and get websites running with as little fuss and wait as possible.

4 Comments

Adi March 18, 2015 at 9:09 am

very well explained. Keep posting…

SIVA SANKAR MOLKA March 24, 2015 at 6:26 am

Good article. Thank you for your post…

J. Moi May 19, 2015 at 9:03 am

Hello,

The empty checking worked well, but the wrong inputs of username and password return nothing, just the login view but without the flash data message [I tried the demo]… Don’t know what’s wrong.

admin May 19, 2015 at 9:57 am

Thanks for you comment moi,seems flash data not working i will check and update the code

Leave a Comment