HomePHP Page 6 - Building an E-Commerce Site Part 2: Managing Users with Sessions
Step 2: Extracting the New Scripts - PHP
This is the second article in a three-part series dealing with using PHP 4 and MySQL to make a comprehensive e-commerce storefront solution. This article covers session management within the store, user privileges, and a few security concerns.
Okay, we've got our user table, let's make screens for the user to log in and log out. Download the mymarket2.tar.gz file and extract it into your web root directory. Note that this replaces the files from the first tutorial.
IMPORTANT NOTE: If you have made modifications to the files from the first tutorial, please make a backup copy and store it somewhere else. The files in mymarket2.tar.gz will overwrite any changes you made to the files from the first tutorial.
We do the same drill from the first tutorial. Download the mymarket2.tar.gz file and extract it into your web root directory. For example, if your web root is in
$ tar -zxf /tmp/mymarket2.tar.gz
Assuming that you've downloaded mymarket2.tar.gz into /tmp. Now, open up the file application.php and change the $CFG->wwwroot and $CFG->dirroot paths to match your server configuration.
Before we dive into the source code, let me explain how I've setup the directories and files. Once you go into the mymarket directory, you will see five directories, and four files. Everything in bold is new to this tutorial:
drwxrws--- 2 ying web 1024 Apr 20 02:05 images/
drwxrws--- 2 ying web 1024 May 4 09:18 lib/
drwxrws--- 3 ying web 1024 May 9 11:20 templates/
drwxrwsr-x 3 lanuser web 1024 May 9 11:20 users/
-rw-rw---- 1 ying web 2074 May 7 14:58 application.php
-rw-rw-r-- 1 lanuser web 1488 May 7 12:21 index.php
-rw-rw-r-- 1 lanuser web 2427 May 7 14:51 login.php
-rw-rw-r-- 1 lanuser web 1040 May 9 11:19 logout.php
I won't go over the files and directories that were from the first tutorial (admin, images, lib, templates) except to say that the scripts inside them have changed a bit. Take a look at them and see if you can spot what's changed <grin>, just kidding, I will cover those as necessary :)
The users directory is where we keep the scripts relating to user functions. For now, it contains scripts to let the users signup for an account, change their password, change their settings, and retrieve forgotten passwords.
The index.php file is the MyMarket homepage. We didn't have one of these from part 1 of this guide because we were only interested in the administrative functions. We have it now only to show a dummy homepage (which we will add to in part 3 of this guide).
The login.php and logout.php files handle the process of logging in and logging out. We've briefly gone over what was involved in logging in and logging out, see these scripts for more details.