PHP Examples - Login.php

From Olmec Jaguar

Jump to: navigation, search

Login.php

Summary

I use this login page to allow a couple of users to update the amateur football team website I admin on. Those users can add match reports, news items, player details etc etc which are all stored in a MySQL DB.


Comments

Creates a simple form that allows the user to enter a email address and password. It then queries the user table on the DB to see if the user exists using the email address and an encrypted password (using the sha1 method which you have to use when registering the password too). If it finds a record then it performs a lookup on the user record to see if there registration has been approved (Note the LIMIT 1, on the end of the sql). In this example I've used a 'category' field. At the moment if this is blank then I echo a message to the screen saying 'their registration has not been approved'. In the future I do intend to use this category field as a method of determining which areas of my site that particular person has access to.

If the user has been approved I set 2 cookies, one I simply use as a display name the other is a user id. I then update the user record with a 'last logged in' datetime and also increment the user number of login count. This helps determine who is most active and also can be used to see if there is a security issue with a certain user. As my users had access to all records in the DB there was no need to segregate/shield certain data at present.

I then re-deirect the user to the admin home page from where they can update/delete/add the various bits that make the website tick. (The logged.php page manages this, I'll add this later)

This script originated from a php book I bought (can't recall the name just now!) and I've edited it for my own particular uses. So far it's worked nicely for my purposes. For Jaguar it may require some tinkering.

I cannot upload php or txt pages at the moment and pasting in the code causes display issues (I gues the html confuses things)


Jaguar

Is there anything we can take from this for Jaguar?

Personal tools