In today’s video tutorial, we’ll be building a login system with PHP and MYSQL. Many, many features will be covered; including MySqli, Prepared Statements, jQuery, Classes, Sessions, Cookies, etc. I bit off more than I could chew for today’s screencast. So, I’ll be creating a Part 2 in the next couple of weeks in order to improve our system even further.
Finished! ….For Now
We’ve managed to get an enormous amount of work done in about forty-five minutes; but there’s much room for improvement – specifically when it comes to optimizing our class files for reuse. Before I let you go, let’s take a quick look at what we’d like to accomplish in Part 2.
What We Need to Accomplish in a Future Tutorial
- Set an expiration date after creating a session – so that the user is automatically logged off after X minutes.
- Allow users to sign up and edit their passwords.
- Update our database to contain “secret question/answer” questions for username/password retrieval.
- Refactor our class files. As I mentioned in the video tut, there are a few procedures that we should remove from our methods in order to promote “best practices”, and increase reusability as much as possible.
- Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


http://www.podprysznic24.pl/ogloszenie-id-8286.html
i’ve made my website how can i access it?
dude its been way over 2 years now…. where’s part 2 at?…
When Dreamweaver put your cursor that far indented, that was its way of telling you that you hadn’t closed all of the parentheses.
I’d love to see a second part to this!
Jeff,
This tutorial is great. I am really happy with this setup, but want to add more to it and would like part 2 please. Please post part 2 soon.
Hi! Thank you so much for this awesome tutorial, it’s very helpful. When I run it on my local computer, it works fine. When I try uploading it to a web host (iPage) though, PHP errors out. Here are the errors:
Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at /*/*/*/*/ipg.*/rovweb/includes/header.html:15) in /*/*/*/*/ipg.*/rovweb/login.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /*/*/*/*/ipg.*/rovweb/includes/header.html:15) in /*/*/*/*/ipg.*/rovweb/login.php on line 2
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /*/*/*/*/ipg.*/*/classes/mysql.php on line 9
Warning: mysqli::prepare() [mysqli.prepare]: Couldn’t fetch mysqli in /*/*/*/*/ipg.*/rovweb/classes/mysql.php on line 20
I obscured some of the names with * fyi. Thank you, Sam
hi i was wondering what other function i could use instead of mysqli as my host has turned it off
When someone tried to log into my website then couldn’t log in why is that? How can I fix it?
For those of you using cPanel Hosting, When you create the database and user (under MySQL Databases) Make sure you give the user permissions on the database. That will probably solve any connection errors. Also make sure you are adding the user and database name as xxx_name because cPanel auto-appends your cPanel username onto the front of the names.. so if your cPanel login name is mike and you have a DB and user named mike as well, the connection string will need to look like this:
define (‘DB_SERVER’ , ‘localhost’);
define (‘DB_USER’, ‘mike_mike’);
define (‘DB_PASSWORD’, ‘YOURPASSWORD’);
define (‘DB_NAME’, ‘mike_mike’);
On another note, and this is probably something for the JS Folks.. when I add the JavaScript into the code at the end of the tutorial, reloading the page gives me a beautiful blank page. Almost like a 500 error, but I can’t find any error message anywhere.
Ideas?
I got it… Forgot to close the tag in the login.php
Hey,
can you told me what’s wrong? it gives me errors
Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user ‘username’@'localhost’ (using password: YES) in /home/gteksi/public_html/gaming/classes/Mysql.php on line 9
Warning: mysqli::prepare() [mysqli.prepare]: Couldn’t fetch mysqli in /home/gteksi/public_html/gaming/classes/Mysql.php on line 20
and i’m new…
thank you!
Kimi
I agree with michael phelps For those of you using cPanel Hosting, When you create the database and user (under MySQL Databases) Make sure you give the user permissions on the database. That will probably solve any connection errors. Also make sure you are adding the user and database name as xxx_name because cPanel auto-appends your cPanel username onto the front of the names.. so if your cPanel login name is mike and you have a DB and user named mike as well, the connection string will need to look like this:
define (‘DB_SERVER’ , ‘localhost’);
define (‘DB_USER’, ‘mike_mike’);
define (‘DB_PASSWORD’, ‘YOURPASSWORD’);
define (‘DB_NAME’, ‘mike_mike’);
On another note, and this is probably something for the JS Folks.. when I add the JavaScript into the code at the end of the tutorial, reloading the page gives me a beautiful blank page. Almost like a 500 error, but I can’t find any error message anywhere.
Ideas?
hello login bye
hello this is me
ssss
Hi Jeffery, totally amazing tutorial…I’m a beginner and that was better than my in-class sessions.Great work. Wish you were local so we could work on my startup!
Thank you very much bud!
Thank you, i was looking for php [ session ] tutorial, and now i learned the basic.
thank you and god bless you
Awesome, but where is part 2, would be amazing to see where you take it
Hi,
Can you please advise when part 2 will be done??
Seems that this tutorial has been completely been forgotten about.
Part 2 would be awesome.
I’m enjoying the tutorial. When’s part II coming out?.. It will be cool..Thanks for sharing!
Amazingly helpful . . . sad it seems that part 2 is not to arrive . . .
Where is part 2?
Using this I get “Call to a member function prepare() on a non-object in *location* on line 20″ errors when I submit any username/pass combos.
very nice..i just used this php for my new website…looking forward more tutorials..
Hi,
I followed the tutorial to the letter by i keep getting the following error:
Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\membership\Mysql.php on line 19.
Here’s my code from the Mysql.php:
conn = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME ) or
die(‘There was a problem connecting to the database.’);
}
function verify_Username_and_Pass($un, $pwd)
{
$query = “SELECT * FROM users WHERE username = ? AND password = ? LIMIT 1″;
if($stmt= $this->conn->prepare($query))
{
$stmt->bind_param(‘ss’, $un, $pwd);
$stmt->execute();
if($stmt->fetch())
{
$stmt->close();
return true;
}
}
}
}//end of class Mysql
?>
I am new to using prepared statements so am not sure where the error is, please help.
im pretty sure i followed all of the videos instructions but when i go to the login page and login in it doesnt do any thing. i think it has something to do with the database or the database connecting to the login
Will a second part of this come out?
verify_Username_and_Pass($un, nd5($pwd));
if($ensure_credentials)
$_SESSION['status'] = ‘authorized’;
header(“location: index.php”);
} else return “Please enter a correct username and password”;
}
}
When I type all that in and try to go to http://localhost/files/login-register/login.php I get an error message that says “Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\files\login-register\classes\membership.php on line 12″ but I can’t find what that error is, or whats wrong.
I added the following to login.php since logged-in users should never see the login-window till their logged out:
if($_SESSION['status'] ==’authorized’) {
header(“location: index.php”);
}
I RESURCH TO VIDEO HISTRY.
Thank you SO much for creating this video. I followed it from start to finish and was able to get everything working the same as your examples. I am still a little in the dark with the PHP side of things, but I have been brushing up on my JS skills on codecademy.com which really helped a lot. Now to find another tutorial on how to allow people to register for their own account using this as an example! Anyone know any good links??
Thanks again!!!!
please is there anyone who can explain how i can create a yahoo sign in page,and the result page where all important informations will be sent to.please i will be very much pleased if i can get an answer
Hello, I was wondering if part 2 is coming out anytime at all. Thanks
I press login and nothing happens :(
the bg.png is missing from the downloaded source
Regards