Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Gabor Galantai
PLUS
Gabor Galantai
Courses Plus Student 17,247 Points

Is there a course on how to handle user login with PHP?

I've finished several of the PHP courses but I haven't encountered this topic yet, even though it's quite an important matter. Any information on where can I learn how to make users log in and how to filter what do they have access to? Thanks.

jack AM
jack AM
2,618 Points

Would you be open to other resources other than whats on treehouse?

Gabor Galantai
Gabor Galantai
Courses Plus Student 17,247 Points

Yes Jack, that's perfectly fine for me if it's not available here. I've looked up some written tutorials but they are a bit fuzzy for my beginner programmer brain.

jack AM
jack AM
2,618 Points

Okay cool, and how have you been accessing your mysql database, through PDO's?

Gabor Galantai
Gabor Galantai
Courses Plus Student 17,247 Points

That's the plan, but I didn't make this part yet. I'm building the site now, and writing the SQL to add data to the database. But I will require a restricted admin login, and separately an open user registration/login option. So I need to know how to make it work, securely.

jack AM
jack AM
2,618 Points

So with this project, I would just like to say, as many tutorials do, that creating a "secure" login system is something you would normally rely on your framework for doing for you (scripting in your password handling/verifications, database work, etc...). This is because frameworks like PHP's, Yii, Laravel, and what not., have been used and tested many times over. And ultimately, you would like to know that your site is secure to the utmost extent that you could possibly make it...

With that aside, and for the awesome sake of learning the system, there are two things you will probably want to familiarize yourself with (if not already), PHP Data Objects, and Session management. This tutorial, http://www.codingcage.com/2015/04/php-login-and-registration-script-with.html, utilizes both to control the flow of the things. It seems like a decent starting point for getting dirty, and getting straight to the point of what you're looking for.

You mentioned earlier, that you wanted to create a different login page for your admins. Might I suggest, just make one login page for everyone, and based on a particular user's, say, user level in the database, that would dictate what gets shown to the client, either admin.php or user.php (just as an example). But that might help keep things steady by following this tutorial, if you run in to a wall down the road. But if not no worries. Also, he uses the html template framework bootstrap, which you can just disregard if you're not familiar with it.

Gabor Galantai
Gabor Galantai
Courses Plus Student 17,247 Points

This looks like a nice tutorial, thanks a lot for the info. I use Bootstrap on my site so that's no problem. I don't use PHP frameworks because I don't know any of them. I saw there are laravel courses here, but I didn't think it would be essential to use a framework. Do you think it's possible to build a site and then just adjust it to a framework later, or would that require to recode the whole thing once again? I was thinking to separate the admin from the users because I thought that would help improve security. But perhaps this is only so in my imagination. :)

jack AM
jack AM
2,618 Points

Its totally possible to implement a framework down the road, so def no worries. And it's better to get familiar with the inner workings of a language anyway before jumping in a framework, I just wanted to keep that in the back of your mind, as people have done the same for me in the same way, and for good reason ;)

If you would like to implement your admin page, like you had planned, by all means. There more than one way to skin a cat, and there is nothing wrong with the way you want to do it.

Gabor Galantai
Gabor Galantai
Courses Plus Student 17,247 Points

Thanks for the supportive thoughts Jack, I highly appreciate it.

2 Answers

Julian Gutierrez
Julian Gutierrez
19,201 Points

Gabor Galantai I have not come across any PHP courses on Treehouse that cover that specific subject but then again there are still some php courses I've yet to take.

Florian Glembotzki
PLUS
Florian Glembotzki
Courses Plus Student 4,370 Points

Do you know these book: "Effortless E-Commerce with PHP and MySQL" by Larry Ullman? Customers have the option to log in and he is impementing an user system with administrators and normal customers. I think this is what you are looking for. The Book is also available on amazon as e-book.