In today's hour long video tutorial, we'll be doing a lot! We'll implement a login and signup form that will allow us to lock down certain sections of our fictional site. As you'll find, working with sessions in CodeIgniter is a cinch!
Catch Up
- Day 1: Getting Started With the Framework
- Day 2: Database Selecting Methods
- Day 3: Sending Emails
- Day 4: Newsletter Signup
- Day 5: CRUD
Day 6: Sessions
P.S. The Logout Button
I forgot to add the "logout" button during the screencast. There was so much to cover, that I was bound to forget something! Luckily, it's really easy. Simply add a link, to the "members" area, which links to the login class, and a "logout" method (login/logout). Then, all we must do is destroy the user's session, and redirect them back to the login form. Download the source code if confused.
function logout()
{
$this->session->sess_destroy();
$this->index();
}
Hope you Enjoy it!
Keep in mind that we're just scratching the surface, in terms of flexibility and security. We can - and very well may - take things much further. But this should get you started!
Thank you, Screencast.com!
- Follow us on Twitter, or subscribe to the Nettuts+ RSS Feed for more daily web development tuts and articles.
Related Posts
Check out some more great tutorials and articles that you might like
Plus Members
Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.











User Comments
( ADD YOURS )icantstop September 10th
Thanks alot, Jeff! Maybe be will be good idea for the next screencast to show how implement and use ajax in CI?
( )Shane September 11th
That would be very good
( )jeanv September 11th
that would be great!!!!
( )aryan September 11th
I’ll also vote for AJAX. JQuery preferred.
( )Anton Agestam September 13th
1 up for jQuery!
fluxish September 12th
yes, ajax please! Also I prefer jquery
( )Anmol September 12th
Yea, Please Please try to show how to use Ajax in code Igniter
( )Vishal September 12th
Yes please some AJAX stuff
am up for it too
( )arnold September 13th
good idea icantstop…jquery + ajax…hopefully
Nick September 14th
One more vote for ajax + jquery
( )Baylor Rae' October 3rd
Yes, please add a video on implementing jQuery in CI
( )Vincent November 1st
AJAX & jQuery +1!
That would be great
BTW, thanks for all the effort you put in these screencasts !
( )Carlos Caniguante September 10th
At Last!!!! being waiting this all week
Thank You!
PD: Hey Jeff It’s seems that your personal domaing http://www.jeff-way.com/ has expired.
( )Hooman Asgari September 10th
Thanks
( )been waiting for this episode
Thanks Jeff
Thanks Envato for teaching us all the good stuff
Look forward for the nex one too
Juan C Rois September 10th
I’ve been looking into CodeIgniter for a while. This and all the previous posts will be very handy when I take the plunge.
Thanks Jeff
( )Mathew Davies September 10th
This is no good, hashing a password with 1 pass of md5 without a salt is not a good idea. Once your database is hacked, hackers can easily look up passwords via a rainbow table. Please reconsider your security implementation.
There are a number of other issues I would fix.
1. Hard-coded link in the “is_logged_in” method.
2. The “is_logged_in” method should be in a library. No need for it to be in a controller.
3. Line 59 of the login controller, assigning the query variable in the “if” statement is pointless, you are not using it.
4. Your logout method should redirect to your index page, not call it. You will end with 2 URLs with duplicate content otherwise.
5. The validate method in the “membership_model” can be improved by changing this :
if($query->num_rows == 1)
{
return true;
}
into this
return (bool) $query->num_rows;
6. This tutorial should be teaching best practices, including a header in multiple goes against the DRY mantra.
-Mathew
( )Jeffrey Way September 10th
Your Md5 reference — For an introductory tutorial to a login system, it’ll work just fine. We’ll cover more advanced security steps in future tuts. You can only cover so much in one tutorial.
( )Jeffrey Way September 10th
Also…
#2 – Well sure. But we can only cover so much in a short tutorial.
#3 – Ahh good point. I must have revised the code, and forgotten that I don’t need to assign that value. Good eye.
#5 – This is true, but we’ll be adding to this section in the next tutorial. That’s why I used the long form.
#6 – Not sure what you’re referring to. We only reference the header from the template view. Did you watch the screencast?
( )Mathew Davies September 10th
For #6
The login_form and signup_form views both include the header and footer files.
Jeff September 10th
You must have accidentally received an old file. I just downloaded the source code, and they aren’t there. Sorry for the confusion.
( )Juan C Rois September 10th
Mathew, I’m sure you are a seasoned coder, but many of us are just learning this stuff, which I believe is the point of the tutorial, I mean to get the basics.
Thanks for pointing out this details, however I don’t think this tutorial is intended for real life implementations.
In my case, I can’t wait to get to this level and hopefully one day I get to learn from one of your tutorials.
Thanks everybody and keep up the good work.
( )Alain September 11th
I agree with Juan.
Robert DeBoer September 10th
I downloaded the movie, and it appears that there is voice problems – it will go out for some seconds and then come back in.
( )Simon September 10th
Hey, I just finished building a login / sign up system using codeigniter.
A couple of days too late this tutorial.
I’ll watch it anyway to see if there is anything I missed.
( )Kamal El Fatihi September 10th
thankyou thats so great i will just start read the post i just had the news by rss
( )Nathan Ledet September 10th
Thanks so much for this Jeff.
I really am learning a lot about CodeIgniter, and programming logic in general, with these tutorials.
Keep it up…they really are helpful and I can’t wait till next week!!!
( )Guillermo Carrion September 10th
Best Weekend gift ever! Specially since I have to give a 2-hour introductory tutorial about CodeIgniter to my fellow co-workers on Monday morning.
Thanks a lot!
( )Ashit Vora September 10th
Awesome. I have started loving CI. I was wondering if there’s any similar framework (easy to get started) for Java.
( )Wiredesignz September 10th
Don’t use the input object inside your models. Pass the data in.
Models are not meant to be aware of the framework at all.
( )eglyph September 18th
+1 to this opinion. I would personally argue against using globals in the code. This way models aren’t portable across different projects, so better approach would to create model’s methods and pass data into it.
( )Kevin Quillen September 10th
Nice video Jeff. I would only recommend not to shoot around so fast with windows and app switching, even I got dizzy hah.
CI looks nice.
( )Javed Gardezi September 10th
thank for this epi… waiting for this..
Thanks a lot for providing download link
Does it contain title for next epi???
( )Hasanga September 10th
Hi,
Nice tut Jeff! very well done!
How about a tutorial using a master page template with CI?
( )ah! using jquery with CI to post form data also would be nice.
Rahul September 10th
Thanx a lot Jeff
( )Kenshin September 11th
I am very interested to see the advanced security CI tut
Thank you Jeffrey for the very good work!!!
( )ricochet September 11th
Thanks Jeffery!
Do I just use the download link & give up checking iTunes from now on?
( )macCesar September 11th
Jeff… I have the same question here…
day 5 never made it in iTunes…
In fact.. The most recent video is dated is 8/24/09 (WordPress for Designers: Day 18)
So what gives!!!!…
( )Jeffrey Way September 11th
I know – sorry guys. It’s a pain, because screencast.com doesn’t automatically submit to iTunes like Blip did. However, the quality is much, much higher. I’ll take care of the iTunes issue this weekend.
ibura September 11th
excellent!! as always
( )Phil September 11th
There’s an issue with CI Sessions in Internet Explorer (at least 6 and 7, but maybe 8 too), in that they don’t really work. There’s a library you can add to make it work properly, and all your code can remain the same. The library uses native PHP sessions, rather than CI’s version.
There’s one on my blog for people that want it
http://www.philsbury.co.uk/blog/code-igniter-sessions
( )Fynn September 11th
Great stuff! I’ve recently watched the first lessons of CodeIgniter (being a total CodeIgniter noob), and started creating my own CMS from what I’ve learned from your tuts and the great Code Igniter user guide! Been playing with it for a few weeks now and already learned a lot.
Thanks Jef! Will watch this one tonight. Keep ‘um going.
( )Carlos September 11th
Nice tutorial, I have been waiting for this one!
How about implementing a remember me, in the next tutorial?
( )Shaun C. September 11th
Awesome Jeffrey, pure awesomeness.
( )Jaap Rood September 11th
I’ve been following your CI tutorials, but this really was the one I was waiting for. Can’t wait to hear more on this topic!
( )Mike September 11th
Tutorial series that makes me wanna use CodeIgniter
( )JT September 11th
Your series is making me convert to Codeigniter! Thanks and keep up the great work Jeff!
( )Myke Bates September 11th
It would be awesome to see some examples of the new cart library releases in 1.7.2. Your tuts are amazing!
( )Tutorial City September 14th
I agree. A tutorial covering the cart class and a bit of an e-commerce website would be very cool.
( )Benoit September 11th
Thank you a lot Mr Way
( )Bobbybazooka September 11th
This is some great stuff. Kudos to Jeff.
( )Would be nice with a part 2 were you show how to tighten the security and so on.
Brian Gottier September 11th
Wow, an hour long tutorial shows the pure dedication that you have to both the tuts+ site, and to CodeIgniter! I have not ever seen an hour long tutorial for anything, anywhere on the net.
I recently released an auth system for CodeIgniter. There are a lot of auth libraries in the CI wiki to choose from, but each with little differences.
If you’re interested in getting a user management and authentication system up and running, you might check out my Community Auth. You don’t have to do it yourself!
Community Auth website w/ download – http://auth.brianswebdesign.com/
CI wiki page – http://codeigniter.com/wiki/Community_Auth/
( )Cody September 11th
Awesome thank you very much Mr.Way!
One request: Would it be possible to export your database and include that within the source!
( )Sri September 11th
This was a very good tutorial. I like how all the different aspects have been combined in this one (things like templating, sessions, new css properties…)
Would like to see an extended version of this tutorial for day 7. Preferably a little more robust with things like different access levels.
Thanks!
( )Juan C Rois September 11th
Hey Jeff, for the little research I’ve done so far, I notice that there are “helpers” for Prototype and Scriptaculous. Do you know if there is one for jQuery?
Also, there should be a link to your screencasts on the CodeIgniter Wiki page. I was going to add them my self but I figured I’d be out of line or maybe it’s better once the series is completed.
Thanks
( )Jeffrey Way September 11th
Yeah – I’m hoping that the CI sites makes some reference to this video series.
( )Juan C Rois September 15th
Well, the Wiki page actually allows user edits, so I actually added the links to the screencasts myself.
This is the link to the CI Wiki page:
http://codeigniter.com/wiki/Category:Help::Tutorials/
Hope it brings even more people to Nettus.
dani September 11th
Thank you very much Jeffrey. I waited so long for such a tutorial.
Cheers
( )Daniel Sitnik September 11th
Thanks for the awesome tutorial Jeff!!
And thanks so much for showing an easy way to load header/footer in all pages, I asked for it last week.
( )Fred Flinston September 11th
This is really cool yeah!!! wohoo
( )umoor September 11th
Hey Jeff I see Screencasts are no more hosted on Blip.tv is there a reason for that?
( )rosnovski September 11th
Jeff,
The only thing to say is well done and please keep them coming. Your other series have done us a lot of good. Thanks Muchacho!
( )C.44 September 11th
Great Tut again Jeffrey, we won’t get bored by a hourlong screencast. On the contrary, we love hourlong screencasts as it shows your dedication and commitment to make a decent vid that we all benefit from. Props to you
One thing i’ve been wondering, you have the default controller login, after that you have the controller members_area (iirc) that actually checks if the user is_logged_in, but how do we check that in other controllers ? I mean, it wouldn’t be right to just stuff everything into one controller and model with a load of functions and views.
Btw, are we allowed to give some suggestions for the next tut ? I’d love to see some ajax action to be honest.
( )Kriesi September 12th
dont know if I am the only one who is encountering these problems with screencast.com content, but downloading the video doesnt really work. I get decent download speed for the first half and then it drops to 4-5kb/sec until it stops completley. straming the video is a pain as well.
would love to see this one on itunes, it seems its the only way to get it for me
( )timo.huber September 12th
thanks again
( )ibura September 12th
@Kriesi, I am having the same problem with the download link.
( )Amine September 12th
Awesome tutorial !! I’ve been waiting for these explanations for so long
( )Really looking forward for a bullet proof security tutorial and a user management tutorial (groups, rights …) !
Thanks a lot Jeff for the effort and such complete tutorials !
tom kirby September 12th
wonderful tutorial,
it would be good to see a tut on more detailed session security, combinding the CI session DB in aswell,
also, i noticed you never checked if a username existed before inserting…
Nice tut! trying to learn CI recently, and this is most defo the best way! many thanks, many more tuts to follow i hope!
( )richard September 12th
Do you plan on making the sql available for the whole series?
( )Tyler Perry September 12th
Very cool tutorial. I have always wanted to learn this stuff. I understand you can only do so much in one video but don’t mind longer videos. Keep it up man. This is extremely helpful when it comes to building websites. This is a skillset that is very important to have.
Thanks
( )Tutorial City September 12th
Great Jeffrey, you’re the man!
( )The web comunity owe you a lot!
Vishal September 12th
Hi Jeff,
Let me first tell you something that I always wait eagerly to watch your Code Igniter Screencast and I’ve learned Codeigniter with the help of all your 6 videos. I really really appreciate your contribution towards Codeigniter Community. You are doing a lot for beginners like me, I really appreciate that! I would like to thank you a lot for such videos. These videos keeps us updated and boost our confidence to learn something new. I saw that Codeigniter 1.7.2 has been released. Hope you will include some new features from that in your videos. Is it possbile for you to include how to used Ajax/Javascript in Code Igniter?
Many Thanks
( )Vishal
Ryan September 12th
Though I was able to figure most of this out on my own previously, I’ve still been waiting on this exact tutorial. Good lookin out!
( )slatron September 12th
Yeah, I just did this for a number of sites over the past few months in CI – but it’s great to see how someone else goes through the same process. No matter what you’re covering – I always pick up little ways to improve my code. And not always in ways directly pertaining to the subject you’re covering.
I’ve been recommending CI to a lot of people – and this is the first place I send them for tutorials. Much better than the ones on the CI site.
Thanks again, Jeffrey! Let’s see some url rewriting in future parts of the series. But really, I’ll watch these tutorials on any CI aspect.
( )Vishal September 12th
I do the same thing, I always recommend all PHP/Codeigniter users to watch these videos
Thanks again Jeff
( )Karl Fredrik September 12th
Hello jeff, really great tutorial – as always
But i get a Database Error :S
http://i26.tinypic.com/2cclzer.png
Whats wrong ?
( )Vishal September 15th
check your database fields! does it says email_address ? is it spelled correctly in your DB table?
( )Alexandr September 13th
Really cool, thx
( )Moyo September 13th
Hey Jeff thanks for everything.
Im having some problems.
I decided to create a permission denied view, as per your advice “not to echo from a controller”
as follows
if(!isset($is_logged_in) || $is_logged_in != true)
{
$bata['main_content'] = ‘permission_denied’;
$this->load->view(’includes/template’, $bata);
}
the problem is after doing this, the permission view loads up, but it still displays the contents of the members area page.
Please what do i do ?
( )xNoir September 30th
I have the same problem, you can resolve it???And dont save the data session
( )bdid November 16th
+1.
Also having this issue.
Mentioned in the tut that die() is not required, but the members area shows without it. But if die() is used, then the access_denied view won’t show…
( )bdiddy November 18th
Got it sorted.
Rather than loading a specific view. Redirect them to a denied page instead.
if(!isset($is_logged_in) || $is_logged_in != true)
{
redirect(’login/denied’);
}
And set up the denied function in the login controller (login.php):
function denied () {
$data['main_content'] = ‘denied’;
$this->load->view(’inc/template’, $data);
}
Starting to wrap my head around the brilliance of CodeIgniter.
kenny u September 13th
Thank You soo much for this tutorial.
this helped me in so many ways
great
( )Kyle September 13th
Great tutorial! Would like to see a CI tut showing how to dynamically create pages like a cms.
( )Stephen Hamilton September 14th
This series is insanely great. This code igniter series along with your “php for beginners” series over at theme forest is really helping me beat the learning curve for PHP. Thanks a bunch Jeffrey!
( )Steve September 14th
Hi Jeff, awesome series, but do you know why this video and any video since 25/08 aren’t showing in the NETTUTS iTunes video podcast subscription?
Last video showing is Wordpress for Designers : Day 18?
Thanks!
( )Dindane September 14th
Although i don’t think you should be learning people the logic behind a login/registration, i do think you are a great teacher. (i did not follow this broadcast). I went on my own after lesson 3 and created my own registration and login (with salting). But i could not get that session to work so i used good old $_session in stead.
I read some request about ajax and Ci, i think this would be a great idea. I made a thickbox with a registrationform and a validation on JS with it but i spent way to much time on it.
So some more claryfication on that subject would be nice.
Just want to end with me saying: you are doing a great job !
( )Hamza Oza September 14th
Thanks Jeff!
( )Sergio September 14th
Quick Question. How do I check if the account already exists. for example two users using the same username can be created twice in the db? That doesn’t sound too good. Im sure its only a few lines of code but can anyone lead me in the right direction?
( )eques September 15th
well, you run a query where you search for a userame that equals to e.g.
$this->input->post(’name’);
q = // here you do your select query to compare
IF nothing is found, you go on with the actual registrationquery so you say something like:
if ($q->num_rows() == 0) {
// here comes your registrationquery
}
Hope this helps
( )Isabela September 14th
Nice work Jeff!I’m working on my bachelor thesis and the log in form was the edgy thing for me.Thanks a lot!
( )Khaled September 15th
Awesome – i’ve learnt alot on my own the last few months (ever since discovering CI), but this was the exact tutorial i’ve been looking for to just link everything i’ve learnt together…
once you’ve got your head wrapped around this – give dx_auth a look – it’s really more than enough for just about any site with what it can do in terms of Authentication…
( )Clint Davis September 15th
Thankyou Jeff,
Started using CI for my new projects.
( )Looking for your new tutorials each week.
iMatt September 16th
I must say a very very nice tutorial Jeff! It covers very much basics.. for what I was waiting very excited!
I was wondering if you could also arrange some tutorials for OOP basics?
Greetz, Matt from Slovenia
( )C.44 September 16th
I have some trouble trying to put the record we pulled from the database when validating login credentials into the cookie/sessiondata.
In the validate function in the membership model i returned $query instead of true so i’d have something to work with. Then in the validate_credentials function in the login controller i added:
$result = $query->row_array();
Now that in itself works and iirc adding the result variable/array to the $data that is later being added to the sessiondata, works also. However the redirect after that doesn’t work anymore. In fact nothing does.
Also, is there a way to get normal error reporting with CI ? It’s driving me completely mad that i’m completely dependant on CI’s errorreporting which is just not cutting it for me.
( )C.44 September 16th
Kinda solved my own problem here. Instead of returning $query in the validate function of membership_model, i first did:
$q_result = $query->row_array();
and then returned that.
After that i could safely use that value in the validate_credentials function to pass it on into the sessiondata. Even the redirect works.
Anyway, i’d still like to see way to enable normal error reporting.
( )Guido September 17th
What do you use to code the CSS and see the changes “on the fly” in FF?
Thanks for the tutorials and keep rocking!
( )Jeffrey Way September 17th
Web Developer Extension for Firefox.
( )Paul Chater November 2nd
You can do it with Firebug too
Natrium September 18th
I’m looking forward to an advanced login-tutorial, with password retrieval, salted md5 (how to do it), check if username is already taken and session management by using the db.
Keep em coming
( )Natrium September 20th
and Ajax with jQuery and JSON also would be nice
( )yellow_leopard September 18th
Thanks so much for these videos, Mr. Way. I’ve spent most of my time on this site learning, and figured it would be a good idea to sign up for the plus membership!
I’m loving it, please keep this series running. One of the earlier comments someone asked if you’d do something with the cart class, and a bit of e-commerce in a future tut — I’d really appreciate it if you would consider doing something with that.
Thanks again.
( )Alex Lofaso September 18th
I am really learning a lot from these tutorials Jeff. Keep up the good work. I can’t wait for the next episode.
( )Egander September 19th
Hey There Jeff
Egander here – I’m a huge fan of the tuts on CI.
Actually – I dont know wether or not, this is the right place – to put out questions… but trying anyway…
How do i make ci change betweens languages ex: english/french
and all the info is loacated on the appriate database …. ???
Nice if you could post a screencast speciic to this dillema
In advance – thank you for the amazing work, you’re putting into this site
( )Pure inspiration – thanks again…
aslam doctor September 19th
I liked that, really nice tutorials series. Thanks you very much for providing this.
I would like to see “Form Validation” & “File Upload” tutorials because I really messed a lot & canceled using Codeigniter in the older version, may be 7-8 months ago. But I hope its lot easier this time.
Thanks again…
( )handoyo September 20th
Thanks a lot for the tutorial series..
( )eBagy September 21st
Thank you very much for these awesome tutorials
( )C.44 September 21st
Jeffrey, any idea when we can expect this episode and the last one to show up on iTunes ? I’d love to keep these things organized
Any idea what the new tut will bring and when it will be released ? You really encouraged me to use this framework and i’d love to see what else is possible.
( )jeanv September 22nd
Hi Jeff, i have to say that you really did a great job, thanks a lot for that. What will be the next step ? Ajax ? Wold be wonderful ! Keep on !
( )yellow_leopard September 23rd
Anyone know how to add the view correctly without it displaying the main contents? I’ve got the view loaded but it displays the members area page as well as the “please sign in” error message. Referencing towards the end when he says to create a view instead of echoing inside of the controller.
( )Roeland September 23rd
This series is awesome! Please keep it coming. I would also like to see some sort Ajax/Jquery with CI tutorial. Best practice methods on implementing it also..
( )Ronny September 24th
Hey Jeffrey, can you show us how to correctly use AJAX operations with for instance jQuery in one of your future CodeIgniter tutorials?
( )Brian September 24th
Hey Jeffrey, great tut as always. All six tuts about CodeIgniter are great. Can You make one tutorial for OsCommerce like shopping cart?
( )punchi September 24th
GRACIAS!!!! Thank you Jeff, awesome tutorials =)
hope the next tutorial have some jquery, it will be great =D
( )Samurai Girl September 26th
Really great tutorial.
i don’t hope you will read all these comments
but still 
) you dont needed to worry about the wallpaper. really
i enjoyed it and even found some moments humorous
You covered quite many things in that single hour. Thanks for the series
( )rookie September 26th
Thank you very much Jeff! It would be great how to make a site with a header, menu, content and footer. It’s a very used layout in web design. You are doing an incredible job! Thank you so much!
( )emcgfx September 26th
Thank you so much for posting my request
Just what I needed. I already have ideas for the next video. PAGINATION
( )Aditu September 26th
How about more secure version with db sessions and more secure hashes?
( )phpQuery would also be a nice tutorial subject. i think there is enough of jQuery tuts – at least those simple ones.
emcgfx September 26th
I agree, following tutorial should be more secure version of this. Thank you Jeff.
( )emcgfx September 26th
Also, I’ve noticed that every view I now create under site controller, is needs to be for members only. Can we have some kind of more unique way of adding like $is_logged_in to the pages we want to be protected and leave other open to public ? Thanks.
( )Isaac September 26th
Jeff,
I saw this video and it pretty much instantly made me love net.tutsplus.com… I will be watching all your videos.
( )neo September 27th
The thing about CI sessions is they do not expire when you close the browser. You have to hack the session files in system to make it work that way… but then it ONLY works when you close the browser. It is on or the other.
I wish CI would provide a better session management.
( )punchi September 29th
I had the same “problem”, as far as I know, CI don’t provide something to manage the “real” sessions (as the user still login, looks like more a cookie than a session), so my solution was use directely $_SESSION (http://cl.php.net/manual/en/function.session-start.php)
If CI can handle this, it will be great, someone knows?
( )Phil September 30th
See my above post – there’s a class to do it using “real” sessions, but called using the same CI functions
Christos September 28th
Very helpful tutorial series especially for newbies.
Are you going to show us something more ‘difficult’ ?
For instance, automatic form generator based on MySQL tables.
Does this sound too advanced?
Thanks and again congratz for your work
( )James Goodin September 29th
If anyone is using PHP 5.3+ and getting a message ‘The URI you submitted has disallowed characters.’ then please go to this site for the fix.
http://davidmichaelthompson.com/2009/09/03/fixed-the-uri-you-submitted-has-disallowed-characters-error-codeigniter/
Also, if using PHP 5.3+ then I also had to remove the ‘&’ characters from a couple lines of the ci code to stop getting the deprecation errors.
Peace,
( )James
Sunil September 29th
Great tool and tutotrial !!!
how do you check for unique username before insert. Is there a shortcut validation rule.
( )Phil September 30th
one way is like this:
Set a validation rule:
$this->form_validation->set_rules(’uname’, ‘Username’, ‘required|callback_username_chk’);
to which your function would be:
function username_chk($str){
$this->db->select(’username’);
$sql = $this->db->get(’yourtable’);
$users = array();
foreach($sql->result() as $username){
$users[] = $username->username;
}
if(in_array($str, $users)){
$this->form_validation->set_message(’username_chk’,'Sorry this username has been taken’);
return false;
}else{
return true;
}
}
not perfect, but works!
( )Alex October 19th
Thanks Phil,
Just one question. If it works, why did you mention it wasn’t perfect? What are the problems with your solution if any?
Burak November 2nd
It loads all the usernames into an array.
The username search should be done on the database side instead.
Javed Gardezi September 30th
Hey!! JW when the new episode is coming it has been long. Please do not put so much gap in the series other old concepts diminishes away….
Every thing has to revised again..
There is also suggestion :
( )Why not give us some practice stuff or material or exercise for this series so that we can continue on our self.
Carlos Vidal September 30th
This is more a question than a comment on MVC.
How do you decide between creating a new controller function and a new controller file?
thanks Jeff!!
P.S.
( )Wich is the best CodeIgniter forum out there?
shin October 1st
Suggestion for the next tut:
Extend this login form with using captcha.
( )David Rodriguez October 2nd
All I have to say is sweet. Keep them coming.
( )Roger Le October 6th
Jeff this was really good stuff. I’ve learned a lot from your brief tutorial.
I was curious, I’m developing an App where I”ll need both Public and “member only” pages.
I was thinking of making a modules and locking down the member only module to require the user to login.
However, that requires me to use someone else’s HMVC library or Matchbox. I think a login library would be better and I’d load it in the controllers I needed.
The other solution would be to copy paste the login code in EACH controller but lets not do that.
What are your suggestions?
( )Chris Farley October 6th
Great tutorial. I have a general question about best practices though. Is there any advantage to having the controller call a model method to validate the login credentials rather than creating a custom callback for the form_validation helper?
I’ve done it the latter way and it seems to work, but I’m interested in other points of view regarding the security and/or transparency of such an approach. I’m afraid that it violates the spirit of the MVC framework by introducing model processing into the controller class.
If that’s the only problem, is there a way to tell the form_validation helper to use a callback from a model class rather than a controller class?
( )Jonathan Lambert October 12th
Am I the only one having issue finding the .sql file to load up for these tutorials? I don’t see anything in the downloads, and I’m not too keen to walk through the tutorial and re-type.
I’m sure this is simple, but I could use some help. I must be missing something.
Help appreciated.
( )Anon October 12th
This video doesn’t load or download fully.
( )Boba October 19th
Great tutorial, i am a complete beginner in CodeIgniter and i am looking forward on more screencast about it.
BTW shouldn’t you close the forms? (You didn’t put </form> or form_close(); at the end of the forms)
( )yabune October 25th
I’m not being able to watch the video…
( )It just gets blank…
But I did watch the other tutorials before.
sebastian otto October 29th
me too, would be very nice if it could fixed
( )Bhaver October 26th
Is anyone else having trouble with the video from screencast.com ? is there another source for the screencast? Love the series so far, really interested in this particular piece.
( )David October 26th
Sorry but this video is not available any longer…. ?!? is not playing and when I try to download it it tells me that the link is broken..
( )JT October 28th
I’m having trouble viewing this as well.
( )Abdullah Alhoshan October 30th
me tooo
( )Stan October 29th
Where can I view this tutorial?
( )Thanks!
Pr0v4 October 29th
I would like have this tutorial too… Is possible have it back?
( )fob October 30th
I also would like to see this tutorial
( )Ersin Demirtas November 1st
Thank you Jeff it was a great Screencast.
( )Ricky November 5th
Good stuff Jeff!
I have a question – is there an easy way to pass messages from a controller to a view? For example, if the user tries to log in, unsucessfully – how would you display a message on the same login page to say “login unsucessful.. etc”?
( )Jared November 8th
Finally getting around to going through all these CI tutorials. There great, keep them coming. It would also be nice if you revisited this section and talked about increased security.
( )Kevin Naidoo November 17th
Thank you Jeff , this video series helps allot , just one suggestion for future tutorials – please make the video size smaller, I come from a bandwidth starved country.
( )Gerardo November 20th
is Chrome for mac available?? I can see you have it installed!
( )Jeffrey Way November 20th
The dev beta is available.
( )Gerardo November 20th
is Chrome for mac available?? I can see you have it installed!
This tutorial is the best so far, AWESOME work, there is something wrong with the player, it stops before it finish, I try to reload, and no luck, im downloading it, to see if it woks better this way.
GREAT WORK, I have learn so much in the part I see.
( )