How do you make a username/password site?

This is a REALLY newb question but…

I have been building web sites since 1998 but have never had to make one with users and passwords … and now I do :frowning:

What is the simplest way forward? I am moderately competent at PHP and mySQL.

The site I am preparing will have multiple users each with several clients and the clients will have all their bumf in various pages.

Am building in Bootstrap using Dreamweaver and Sublime Text … Any thoughts gratefully received.

Oh I tried looking on t’internet but could not find anything useful. Appropriate search terms would also be appreciated.

TIA

Steve

You can use something prebuilt, which in my mind is the better way to go then reinventing the wheel - unless you need a very special wheel.

Use a framework, which has authentication built in or easy plugins for it (like Laravel, etc) if you’re willing to use something so comprehensive.

Or use a smaller auth system without the extra stuff… AngryFrog PHP Login Script comes to mind.

You could also just use a CMS like Wordpress, Drupal, etc. that has user systems built in if you’re willing to tackle theming for one.

I learnt how to do this with Kevin Yanks php/mysql book. (from sitepoint). I was certainly not competent at the time
Generally its pretty easy especially if you have a beginning in php / mysql to make login scripts and a user DB, however it quickly becomes more complex depending on what you want users to do. Will you have admins? Will they manage users? will you have levels of users?

If you want a crash course, download a php forum install it and look at their login page / db tables. That’s about as complicated as you will get…

I have to agree with @jeffreylees if you can use something pre made and easy to use, do so.

On the other hand, if you specifically want it to be a learning experience for PHP/MySQL or want to learn authentication, @Andy_Blueman’s method of learning from a book is perfect. Or video tutorials, if you prefer. I learned authentication by dealing with one that I already had in place on a site, but if you’re starting from scratch, a book/lesson might be easier.

Eh learning from a book is not usually my cup of tea, but I read the first chapter free and I wanted to learn PHP Mysql and his book was nice for newbies. I was new to everything back then :smiley:

Gotcha. I can’t learn from books well… which is weird because I love to read, leisure-wise anyway. I’m going to tackle some tutorials later this month for a new language, either written or video… we’ll see how it goes.

When I was new to PHP I was given a freelance job, PHP based custom cms site to overhaul and had no backup… the nights spent unpaid learning stuff… blegh. It was a good thing though. I still think I’m a PHP newbie, in relation to other people, but /shrug.

Hi,

User authentication <language of your choosing>

I found this the other day. It seems to be reasonable.
Other than that I can second Kevin Yank’s book, or what jeffreylees said about using a framework (I just did something similar in Rails and it was pretty straightforward thanks to ActiveModel’s has_secure_password).

Dear all

Thank you for that. As nearly everything I know is courtesy of young Mr Yank I know where I should go next :smile:
Thanks for the timely pointer.

OK been looking at Laravel and it looks fantastic - particularly for DB manipulation (SQL over more than thre tables makes my head hurt) BUT… I am not understanding a fundamental point.

At the end of a Laravel build process what do you have??? Do you get a zip of PHP pages or does it have to stay withing the framework?

I can run it at home but running it on a hosted service would be impossible I ma guessing.

I suppose I could use a spare laptop here as web server but nervous about response times!

Grateful for clarification about what I actually produce in the end if I start working on Lravel.

Thanks in advance.
Steve

Why would it be impossible to stay? Typically you’d keep the whole thing, although in a production environment you might structure things slightly differently, or you might copy over the dependencies instead of letting them be fetched by Composer. But essentially… Laravel would stay?

What you produce at the end is an application that runs under Laravel. I’m not familiar with Laravel specifically, but frameworks generally allow you to run several applications under just one installation of the framework. Like Wordpress, Laravel is designed to work on hosted services, so installing it on a hosted service shouldn’t be a problem nor should the response time be unacceptable.

If you search Google for [php login system], you should get lots of hits.

It didn’t seem like your original question was answered, though. A common way to implement a login system is to use PHP sessions (the $_SESSION variable.

First, you have a login form, basically user id and password. When someone submits the form, you check the user database to see if there’s a row that matches what was entered. If there was, you set a session variable.

$_SESSION['user'] = $login;

Anything like that will work. You may elect to save the user’s name or just set something to TRUE to know someone is logged in.

You also want a link to logout with code that unsets the session variable you set, after which you can use the PHP header statement to redirect the user to the login page.

Then, on every page in your project that shouldn’t be accessed without logging in, the very first lines should be:

session_start();
if ($_SESSION['user'] == FALSE) {
    header('Location: http://www.example.com/login.php');
}

On your login page, you start the session but of course don’t check to see if nobody’s logged in or you’ll get an endless redirect. But that’s pretty much it. Obivously, you can also set up form to register users, retrieve passwords, etc. but the above is the basics of how it works. Hope that helps. :smile:

OK that’s good to hear. Basically after a first long look at Laravel it looks SOOOOO powerful and reusable that it looks a very good investment in terms of learning. But I am going right back to basics first.

I have never done any OO work (finished my computer sci degree in 79) so first up I am am doing a lot of OO basics learning.

The I am specking the project fairly comprehensively then Lartavelling it.

I am, hosting with Godaddy and they seem very unaware of Laravel. I am worried about setting environment variables etc on a hosted setup BUT as there are specialist hosters out there offering hosting for $5-10 it is not such a big deal if I have to migrate (although I find GD customer support very good).

Anyway guys got Laravel up and running. Now just need to work out what the heck I am doing :slight_smile:

Thanks for all your help and observations.

PS Robert that was a beautifully succinct outline of how to do it. If I do NOT Laravel I will use that, if I do it will be a one line command.

Thank you. I’m glad you found it helpful. I’ve been using a framework called Code Igniter. Apparently it is no longer being developed, but it is about the simplest MVC framework out there. I’m using it as my introduction to MVC development. Give it a look if Laravel is too much framework all at once.