There are a few things you should know before you attempt to use this script. The next release of PHP will have register_globals set to Off by default. You’re encouraged to write your scripts with this in mind, in this article we won’t be using normal variables, we will be using
$_GET... etc. These were introduced in PHP 4.1.0.
We will also be using sessions with PHP, if you don’t understand sessions, or don’t know what they are it would be a good idea to read the page so you can understand the coding, and edit it to your needs.
I will be using the PEAR::DB classes to access the database, so you can easily make the scripts work with whatever database you are using. If you are unfamiliar with PEAR::DB read this great article: Abstract PHP’s database code with PEAR::DB.
With this in mind, I recommend using a .htaccess file (if you use apache) to set some PHP values, use the following, if relevant.
php_value register_globals Off php_value track_vars On php_value arg_separator.output "&" php_value arg_separator.input "&"
We want a system that will allow a user to ‘login’, preserve that user’s login data across multiple requests, allow them access to certain areas only when they are logged in, and allow them to be able to logout. So let’s think logically, what do we need?
- User database, containing their password, username, and some personal information to create a community feel.
- Allow them to ‘sign up’ if they aren’t a member.
- A method of checking whether or not the user is ‘logged in.’
- Allow them to ‘log in’ if they’re not.
- Allow them to ‘log out’ when they are done.
Now we need to turn that logic into code, so let us continue….