#63: A Simple Login System

On certain websites, you want a simple authentication system for administrative purposes. Smaller sites with just a couple of administrators don't require a fully fledged login system with individual usernames; you just want to keep out the riffraff. One example of such a site would be "#54: Uploading Images to a Directory" on #54: Uploading Images to a Directory.

Here is the code for single-user authentication. The general idea is to set a session variable named $_SESSION["auth"] to completed when logged in.

We define the password first. As usual, we do not store plaintext passwords. This one is an MD5 hash—you need to change the string to one that you generate for yourself. You'll see how to do this shortly.

<? $enc_passwd ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.