How To Create A OOP PHP Login System For Beginners | OOP PHP & PDO | OOP PHP Tutorial

preview_player
Показать описание
In this PHP tutorial you will learn how to create a login system in PHP from, and how to show content after being logged in. You will also learn about error handlers, and MySQLi databases, which includes how to make a login form and a signup form.

I am aware that this is a very long video, but I promise it will be one of the easiest guides you will ever find on how to create a OOP PHP login system from scratch!

If you get any errors during this tutorial, make sure to check out my solutions at the very bottom of this description! :)

➤ LINKS

PDO vs. MySQLi links:

➤ GET ACCESS TO MY LESSON MATERIAL HERE!

First of all, thank you for all the support you have given me!

I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!

I am now using Patreon and YouTube Memberships to share improved and updated lesson material, and for a small fee you can access all the material either from my memberships or Patreon, depending on your preference. I have worked hard, and done my best to help you understand what I teach.

I hope you will find it helpful :)

➤ ERRORS YOU MIGHT RUN INTO!!!

▸"unexpected }"
If you get this error message:
Parse error: syntax error, unexpected '}'
Then it is because you forgot to close a ) or ; somewhere.

▸"unexpected ;"
If you get this error message:
Parse error: syntax error, unexpected ';'
Then it is because you forgot to close a } or ) somewhere. Probably because you made a mistake with your parenthesis near the "empty()" functions in your signup script.

▸"hashed pwd error"
If you get an error in the script when you hash the password, then it is because you decided not to follow my steps exactly in the video when I created the database table. Make sure you DON'T set the varchar() to a lower value! When you hash the password it will take up a lot of space in this column, and if you set a lower number then it won't fit!

▸"signup=success but database is empty?"
Here there might be a few reasons for your error. 1st is that you made a syntax/spelling mistake in your code. And yes you will claim that your code is identical to mine, but in 90% of the cases people claim this, I still find a syntax error in their code. So check your code for errors!
3nd reason might be because you didn't follow the tutorial 100% when we set up the database at the beginning.

▸"HTTP ERROR 500"
HTTP ERROR 500 is a server error, meaning that you are most likely using an outdated version of apache or mysql. Try updating your servers and make sure that you are using the latest version of PHP.
Рекомендации по теме
Комментарии
Автор

👉👉I MADE TYPOS IN THE VIDEO YOU NEED TO FIX!

👉ERROR 1:

In login.classes.php inside the getUser() method, I made two important typos that will make your code not work. (WHOPS! 😅 ty Sentinel Corps for letting me know)

The first SQL execution should be:
$stmt->execute(array($usn, $usn));

The second SQL execution should be:
$stmt->execute(array($usn, $usn, $pwdHashed[0]['user_pwd']));

👉 ERROR 2:

As someone pointed out in the comments, using rowCount() to check how many results we get when we query the database, isn't a method that work in all database types. Instead you should use count() after you returned the data. Make sure you do it ALL PLACES where you SELECT from the database. 🙂

SO INSTEAD OF:

if($stmt->rowCount() == 0) {
$stmt = null;
header("location:
exit();
}
$profileData =
return $profileData;

IT SHOULD BE:

$loginData =
if(count($loginData ) == 0) {
$stmt = null;
header("location:
exit();
}
return $profileData;

👉 ERROR 3:

If you get a "undefined variable $result", then it is because your editor doesn't like when a variable is declared without a value assigned to it.

To fix it, change:
$result;

To:
$result = false;

👉 BEFORE YOU COMMENT ABOUT LESSON MATERIAL:

And for people who "want my lesson files for free", here is my answer to that. 🙂

My subscribers has voted on me not including CSS in my future videos because it took too long, and because you already should know HTML/CSS at this point. This is not a HTML/CSS tutorial, and even so you are not supposed to "just copy" from this video, you are supposed to "learn and apply" to your own website. People have already supported me on Patreon to get my lesson files, therefore I won't suddenly make it free to download.

People who think I'm obligated to "give my material out for free", have gotten the wrong impression about what rights you have. The free educational videos I make are a product I put a lot of effort into, and I can distribute it however I want. Just be happy that ALL my videos are free, and not on Udemy for $15. 😉

I have seen some angry comments say that I'm "putting up paywalls" for my content, which would imply that you couldn't follow my tutorial without paying for my files... So let me debunk that really quick...

There is NO "extra" PHP in my lesson files, that you won't find in this video. The "lesson material" is meant for people who are making mistakes or typos in their code, and would like my personal files to compare to see where they made mistakes. Or for people who want MY HTML and CSS. 😊

This is how I run my channel so deal with it. 🙂 I won't argue with anyone about it.

Dani_Krossing
Автор

Took me three days to finish your Object Oriented PHP Tutorial and man, oh man, did I learn more than what my uni professor is teaching us. Kudos to you and thanks a lot, sir Krossing! You are an inspiration to me. Keep on coding and I'll keep on following!

lancemartija
Автор

Hey Daniel.
I wanted to thank you so much for your effort on these tutorials. Your HTML, CSS, JAVASCRIPT and PHP courses helped me to achieve higher marks in my Web design assignment. Your tutorials are the only things that I have looked upto and followed. You are a fantastic teacher. I don't normally leave comments in YouTube but I wanted to thanku by leaving this comment to thank you for sharing your knowledge with everyone else. For anyone who look forward to learn and develop their skills on Web designing this is the place to learn.

thenukawickramaarachchi
Автор

as always Dani, providing premium dev content for free, you've saved me so much through my uni course. Much love bigman

Big-Timbo
Автор

Thank you for painstakingly explaining everything you do. I'm sure there are many people (like myself, a rookie) who feel anxious if we deviate from anything explained but you make it very clear what is important and not important to have copied exactly. Thanks dude!

em.pxthetic
Автор

Hi Daniel,
I started watching your basic HTML & CSS courses about 2 years ago, after looking to move into front-end programming as a new career.
2.5 years later I am now a mid-level front end developer in a fantastic career and on my way up.

I want to owe a huge part of it to your early tutorials, making the learning process enjoyable, else I would have probably stopped very quickly.
Love your content, keep it up :)

alfie
Автор

My gosh, man... I literally just finished the PHP login system that you posted on October 11 2020 yesterday, now you come out with this!!
This is awesome!!

jammincoder
Автор

I'm so glad to see you doing tutorials about programming again. You're so easy to understand when explaining things. Thank you so much

Rafael-esdp
Автор

Dani! I followed all your PHP tutorials, very clear easy to follow and understand! I have some basic PHP knowledge already so this made my life easier. Thanks and please keep up the good work! Please release more like this. With these tutorials i managed to make a fully fledged login and register system. Only thing i am missing is 2FA. :)

pixelrangerstudio
Автор

Been waiting for this tutorial for over a year now and finally came. I appreciate you man, thank you so much. Love from South Africa. 🇿🇦🇿🇦

i.t.starters
Автор

Hello Dani. You've been a great php teacher to me. Following your php tutorials I can clone unsplash with basic login system, sign up system, password reset, and how to upload files/photos. Thank you so much. But if you could show some love and do a video on php teaching us how to login with cookies and how to keep users logged in (remember me) with cookies. If nobody has asked u to. I hope you do one of your greatest fan this favor. Thank you so much Dani

khwesigysst
Автор

Literally, this is one of the best PHP project video on YouTube. Thanks Dani👍🏾💯

a-factoracademy
Автор

i just started php and watch almost playlist and write notes. and i can say im getting the hang of it thank you very much sir youre a great teacher

charmcaster
Автор

Splendid video! And valuable comment about possible errors! Absolute gem in the world which tries to ignore PHP. Thank you Dani!

astratow
Автор

This video is definitely worth watching for anyone new to PHP registration and login forms.
It is simple, concise and very educational.

cxiitsq
Автор

Great tutorial. I love your teaching style. I also love that your transparent with your typos and mistakes. Helps me know that its just part of coding.

obsidian
Автор

Great tutorial 🔥🔥 Here are couple ideas I'd love to watch
1) CRUD
2) Routing System
3) Composer basics

Rehaaabek
Автор

It's just crazy how this man is able to make such good videos, KEEP IT UP!

jamalmammadzada
Автор

rip to the people who did the tutorial in 2018, then realized there's a new one, AND right as they were finishing, this came out. LOL (totally not me)

jamalmammadzada
Автор

Dani, you are the best on the web imho. You've been teaching me for years and I keep coming back.

ThePancakeJedi