Creating a Login Script for a PHP/MySQL Blogging System (
Page 1 of 4 )
In this three-part tutorial we are going to be creating an open blogging system. We are also going to provide scripts that will make it possible to switch to a closed blogging system. This article, which is the first part, will cover the creation of the login scripts for a closed system.
The file for the login script can be downloaded
here.
- An open blogging system is a system that allows anyone to contribute to a blog without having to register. In many cases, it also allows any user to start a new topic that will then have its own replies, as opposed to just commenting on a topic that the blog owner started. This kind of blog is suitable for people who have just created a website and do not have a lot of web traffic.
- A closed blogging system is one that requires registration and allows most users to contribute to a topic instead of creating their own. This kind of blog is suitable for people that have a lot of traffic on their websites.
In the first part of this article, we will create a login script for those of you who prefer a closed blogging system. You can skip this part if you wish and come back next week to check out the next part in this series, which will deal with creating a blog if you are not interested in a closed system. The login script will have a MYSQL table which it will reference to verify the existence of a user at login. It will also have various scripts that will help register a new user and retrieve forgotten passwords.
Login Script
The login script will have the following pages:
- Login.php - Enables users to log in.
- Logout.php - Enables logging out.
- Register.php - Creates new users.
- Password.php - Password recovery.
- Messages.php - Handles error messages.
Let's create a table that will gather the following information about a user:
- Username
- Password>
- Level
- Admin - This will be the moderator of the system
- Normal - Normal access rights
- Date_joined
- IP Address - Enables us to identify and ban users.
- Email - Used for password recovery.
- Isbanned - Enable us to ban users
Here's the table:
CREATE TABLE `user` (
`id` int(5) NOT NULL auto_increment,
`uname` varchar(98) NOT NULL default '',
`pw` varchar(98) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`date_joined` datetime NOT NULL default '0000-00-00 00:00:00',
`ip` varchar(20) NOT NULL default '',
`level` varchar(10) NOT NULL default '',
`isbanned` enum('yes','no') NOT NULL default 'no',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=11 ;
As you can see from the table layout, the table gathers a lot of information about a user. The most significant item of them all is the "isbanned" field. This field is responsible for checking whether or not a user is banned. The "ip" field stores the IP address of the user, which will be used to reinforce the isbanned status of a user.
Simply copy and paste the code into your PHP admin and run the SQL.
 |