In this tutorial, I will show you how to build a simple login system consisting of a login page, register page, forgotten password page, email activation, logout page and finally a users online page. I made this tutorial to primarily target new-to-PHP developers, due to the fact that, when I started, I noticed the lack in quantity of basic login systems. Therefore, I decided to make one myself giving high quality advice on how to make your first login system with a users online script! Join today!
Join Tuts Plus

For those unfamiliar, the family of TUTS sites runs a premium membership service called "TUTSPLUS". For $9 per month, you gain access to exclusive premium tutorials, screencasts, and freebies at nettuts+, psdtuts+, and vectortuts+! For the price of a pizza, you'll learn from some of the best minds in the business. Join today!
- 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 )Meshach August 5th
Oh man…
I wish this wasn’t a plus tut.
( )lawrence77 August 5th
Me too….
Soon we join and learn that… :cheers:
Thanks nettuts….
( )Bloody Mary August 5th
This network is still not accessible if you don’t have a credit card!
Change the subscription system so that all people around the globe can access and enjoy learning from this resource.
Did you read that,Mr.tutsplus ?
Dario Gutierrez August 5th
I agree with you guys! Looks good tutorial!
Marcus Setchell August 5th
Thanks for being interested in my tutorial and im sorry that you guys cant read it =[
Marcus
Fynn August 5th
Yo Bloody Mary,
Tuts plus “Plus” (?!!) account is also accessible via Paypal. So that shouldn´t be a problem considering credit cards right? At least not in the Netherlands..
By the way looks like a great tut!
lawrence77 August 5th
no problem Marcus….
We join soon and read that……. :thumpsup:
Laneth August 5th
I am in Australia and subscribed with the 3 Month option via PayPal – I don’t have Credit Card and if I don’t have the funds in the PayPal account, it automatically comes from my bank account. Handy really – How else would one pay, if not with a Credit Card or PayPal?
SykeS August 6th
I have PayPal, but I can’t buy Plus. Credit Card is needed…
setare August 10th
its a good idea
jlapitan August 6th
me too.. i wish i can afford it.. awts… really love to have a tutsplus account…
( )Guario August 5th
This is something I’ve been looking for a while now. I need a basic PHP login system that can also reset passwords. I’m trying Kohana as a PHP framework and it has a basic Authentication module, but it does not include a reset/forgot your password functionality.
I hope this or something like this gets put on the regular tuts site.
( )Johnathan August 5th
There’s no video?
( )chrisberthe August 5th
It’s pretty good, but I found there to be a few grammar mistakes + all throughout the tut you had:
which I found to be pretty entertaining
( )chrisberthe August 5th
Doh… t’was html code I posted. You kept linking a stylesheet called style.htm, funny.
( )Marcus Setchell August 5th
I dont know why that is, XD how can i correct it? :\
Laneth August 5th
Marcus – I’d contact Jeffrey to see if he can’t either update it or allow you access to update it yourself. At least that would be my first step.
Jeffrey Way August 6th
I’ll fix that today.
Marcus Setchell August 6th
Okay thanks and could you sort my SQL file too please as stated below by David Moreen.
Thanks a lot =]
Chad August 5th
I’ll have to read through this later this evening but I’m curious about the Full-Featured Simple Login System.
( )barry August 5th
Why do you guys complain so much?
( )enatom August 5th
guys its not that hard, :-
register, send activation link, md5 (which is easy stuff), sessions, mysql.
I just finised writing my own system with sql injection etc and lots of security, in less than 5 days, tbh i think more Advanced tutorials should be PLUSed. not this.
( )Jedrek August 5th
I agree
( )David August 5th
I disagree, plus doesn’t mean advanced – it should mean higher quality that teaches something very valuable. Just because it’s easy or basic to some doesn’t mean it isn’t really valuable to others, you know?
( )billgates August 6th
Well, I would disagree also. Consider this site is visited by lots of front-end web designers that do not know php (yet?)
( )David Moreen August 5th
Your mysql dump file is not formatted correctly and is generating errors, when I try to import. Very nice tutorial though.
( )David Moreen August 5th
Here is the proper dump for everyone:
–
– Table structure for table `users`
–
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`online` int(20) NOT NULL default ‘0′,
`email` varchar(100) NOT NULL,
`active` int(1) NOT NULL default ‘0′,
`rtime` int(20) NOT NULL default ‘0′,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `users` (`id`, `username`, `password`, `online`, `email`, `active`, `rtime`) VALUES
( )(1, ‘testing’, ‘testing’, 0, ‘fake@noemail.co.uk’, 0, 0);
kevinsturf August 5th
Ill have to read through this one later. I would really love to build a login system
( )阿呆 August 5th
It’s sorrowful that I cann’t watch it..
( )Mike August 5th
In place of the protect function could you just wrap your $_POST elements with mysql_real_escape_string?
( )hari August 5th
Well I am glad to be a member.
I would love to see some tuts for commerce sites. I was researching prestashop. But you hardly find any tips or tutorials.
Keep on rocking
( )ARIFUR RAHMAN August 5th
This tutorial my be free as there are standard tutorial on net about login.
( )One other issue. As there member system need credit card so that many user do not use this. So will you change the subscription system.
Soner Gönül August 6th
Thanks man! It’s great!
I will use this
( )Kiran August 6th
I think i need to beocme a member just to see this!
( )Kiran August 11th
@Jeffrey Can I subscribe to the plus service for one month and if so what do i do? I converted $9 to GB and its only a £5 that’s good value but i only want it for one month
( )Peewee1002 August 29th
You can do that.
I am pretty sure.
Marcus Setchell August 6th
Hey thanks alot for all the great comments guys, and thanks for sorting out my SQL file David. I will admit that when it comes to SQL im not one of the most confident people but i always give it a go.
As for the comments about it being basic, i have stated at the begining of my tutorial the fact that i have written in for new programmers
“I made this tutorial to primarily target new-to-PHP developers, due to the fact that, when I started, I noticed the lack in quantity of basic login systems.”
Yes Mike, you could just wrap you $_POST data with the mysql_real_escape_string() function, i just do my own function out of personal prefference.
Again, Thanks a lot guys
( )Matthew Mancuso August 7th
I believe it would be easier to write protect instead of mysql_real_escape_string
… make it easy on yourselves!
( )James August 6th
People, it’s 9 bucks a month man. Lynda.com charges 25 a month just for videos. No written tutorials.
( )Elizabeth K. Barone August 6th
I only just started nettuts, but this is the first members-only article I’ve seen on any of the tuts+ sites.
What’s interesting is the number of web and web-only publishers who are now charging for content. It seems to be growing quickly, but is it beneficial to the website? I’m especially concerned because a lot of users, as some stated above, will just go elsewhere for the content. (I already have a book, PHP Solutions by David Powers, that covers building a login system.)
I wonder if charging users for content is more profitable than charging for ad space, and if the average user will stand for it. Personally, I wouldn’t buy a subscription to nettuts — only because I use a lot of similar sites and paying subscriptions to all of them would be very expensive, much like buying subscriptions to several magazines in the “old” days would be very expensive.
Still, I think it’ll be interesting to see how this new model plays out…
( )Elizabeth K. Barone August 6th
Yikes, that first line should say, “I only just started USING nettuts,” lol!
( )Jeffrey Way August 6th
Eiizabeth – The PLUS service is simply for those users who wish to have access to more tutorials and screencasts. We offer 5 high quality tutorials every week for free on this site that will keep people from going elsewhere for tutorials.
Marcus Setchell August 6th
I also think that a premium section is a good idea and should be kept. This is because its exactly the same as what you said before, in fact better. You had to pay for the book? well imagine paying for a book that updates every week, you can ask questions if you become stuck.
I personally would rather pay to be a premium meber for nettuts+ than pay for a book.
But on the otherhand taking into account other people have different opinion and i see where your coming from. There are great resources on the internet for free. I dont think anyone here can say they have never used some, but then nettuts is not a webpage displaying tutorials. Its a community of developers trying to help each other out a bit.
Please no one take this offensivly it wasnt meant to be just adding my opinion
and i respect everyone elses opinion =]
Web010 August 6th
There are many tutorials on nettuts about membership systems, why is this one so special to be PLUS?
( )connor August 6th
Due to the shear detail in it. I have read it and it is worth the 9 bucks.
( )barten August 6th
is this system secure?
( )Brian August 7th
That’s gotta be some tutorial. I’ve got a nice CI authentication and user management system that I wrote, and it’s at about 2000+ lines of code. It has various modes of user registration, password recovery by email link, user search/sort/update/delete, multi-levels of users and admins, supports disabling the login per IP or per username, optional persistent login, and a lot more. Best of all, it is CI, so it uses flash sessions for form posts, form validation, input filtering, active record for clean sql, and all that good stuff we love about CI. I’m going to be fine tuning it over the next few weeks, and hopefully post it in the CI wiki shortly after the CI 1.7.2 release. The CI forum makes it sounds like 1.7.2 is really close to being released. A tutorial for making my system would take… many many hours. Fortunately, using it is really simple.
( )Amine August 11th
Really Interested by it since there are no bullet proof and clear tutorials about that in the codeigniters forums … and I’ve been searching for a while =) !
( )Kiran August 11th
Where do i go specifically to view what you have made (CI novice)
( )Darrel August 7th
I wish you had written this so that the passwords are stored encrypted. Then have the “forgot password” section send a new, random password. Of course then you’d need a “reset password” section so users could their preferred password back in.
( )otumara jolomi August 9th
My country is not on the list on the payment page so i can’t even get a plus account. Not fair at all
( )raoul August 12th
Hi there,
I’ll maybe take an account not just for this tuts but… Is this tut work with a data base ? like sql or so ?
Thanks !!
( )R. from france.
Some Macedonian August 17th
I think it’s fair enough for them to charge for some tuts, cause the free tutorials here are among the best you can find online. Plus you don’t have to pay if you don’t want to. We should be grateful for sites like this, cause they have made the effort to help the community, but people are always greedy, you give them the finger, they want the whole arm. If you read all the free tutorials about PHP here and you are not able to do full featured login system on your own, then you should seriously think about changing your profession to something else.
( )Brandon S. Adkins September 24th
Looks like I might be getting a Tuts+ account to view this one.
( )laCiutat October 5th
Hi Marcus,
Thanks for the great tut, it’s perfect for a crossover designer learning the ropes.
I have a few questions:
I keep getting these errors that I feel are pretty simple, but since I’m a php n00b I don’t know how to fix them. I’ve listed the, page, error notice, and the relevent line of code below:
———————————————————————————————
/login.php
Notice: Undefined index: submit in C:\wamp\www\cms sci\login.php on line 22
line 22: if($_POST['submit']){
————
/register.php
Notice: Undefined variable: INFO in C:\wamp\www\cms sci\register.php on line 100
Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost”
port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\wamp\www\cms sci\register.php on line 100
line 100: mail($email, $INFO['chatName'].’ registration confirmation’, “Registration email “.$username.
—–
/forgot.php
Notice: Undefined index: submit in C:\wamp\www\cms sci\forgot.php on line 22
line 22: if($_POST['submit']){
——————————————————————————————————-
Everything else works fine. Any advice on what’s going on here would be greatly appreciated!
Thanks again.
( )Moira October 6th
Thanks for the great tut. How do we keep people out of the restricted area if they’re not logged in? I tried using the UsersOnline code, but it just says “restricted area…” but then shows the content just the same.
Thanks
( )Houston Graham October 6th
Can there easily be added a Admin Approval step? I would like to approve the new accounts before they have access. Thanks.
( )Blaise October 15th
Hey, I keep getting a header issue: Cannot modify header information – headers already sent by ……
( )Anyone know how to fix this? Ive tried removing white space and the issue persists.
vic October 20th
who/how do I contact regarding clarity/help on the ‘back to login.php’ step of this plus tutorial.
in the mentioned step, when I add the the ‘back to login.php’ to step 2 ‘creating the login page’, it doesn’t function as it is written in the tutorial.
sorry, but there wasn’t any documentation in the downloaded material on who to contact if things didn’t seem right.
( )mee November 13th
there are some parts missing in this tut! like keeping people out of the private area…
( )David Henderson November 14th
Hi,
I am trying to run the SQL for the table users and keep getting the following error:
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘0′,
`email` varchar(100) NOT NULL,
`active` int(1) NOT NULL default ‘0′,
‘ at line 5
Does Anyone know what may be causing this?
( )