PHP
  Home arrow PHP arrow Page 7 - Building an E-Commerce Site Part 2: Ma...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building an E-Commerce Site Part 2: Managing Users with Sessions
By: Ying Zhang
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 30
    2000-05-16

    Table of Contents:
  • Building an E-Commerce Site Part 2: Managing Users with Sessions
  • Assumptions and Requirements
  • Primer on Sessions
  • User Management and Privileges
  • Step 1: Creating the Users Table
  • Step 2: Extracting the New Scripts
  • Step 3: General Script Changes from Tutorial 1
  • Step 5: User Scripts
  • Step 6: A Note on Security
  • Step 7: Putting It All Together

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building an E-Commerce Site Part 2: Managing Users with Sessions - Step 3: General Script Changes from Tutorial 1


    (Page 7 of 10 )

    Okay, now let's go over some of the changes we've made since part 1 of this tutorial. Some new files were added, and some scripts were changed to include new functions.

    Added 2 new configuration variables:

    1. $CFG->wordlist, points to a text file containing a list of words that we will use when generating random passwords, more on this later.
    2. $CFG->support, stores the email address of the MyMarket support staff (the non-existent ones :).

    The value of $ME is now set by a function called qualified_me(), instead of just using $SCRIPT_NAME.

    A bunch of new functions have been added to stdlib.php to make it more useful:

    • strip_querystring() Changes things like "foo.php?abc=xyz" to " foo.php"
    • get_referer() Returns the URL of the referring page
    • me() Returns the name of the current script
    • qualified_me() Returns the name of the current script with the leading http:// or https:// qualification
    • match_referer() Returns true or false depending on if the referring page matches what you want
    • redirect() Uses META tags to redirect the client's browser to another URL
    • read_template() Used to read a template file into a string

    The file mymarket.php contains some standard functions that are used by this application. For example, the build_category_list() function that used to be in admin/products.php has been moved here so that we can use it in other scripts as well (eg. the admin/categories.php page). The other functions in this script are:

    • is_logged_in() Returns true if the user has logged in
    • require_login() If the user hasn't logged in, show them the login screen and make then login first
    • require_priv() Make sure the user has a particular privilege, if they don't show an insufficient privileges screen
    • has_priv() A less severe version of require_priv(), this just returns true or false depending on if the user has a particular privilege
    • build_category_list() Our favourite function moved here from the admin/categories.php script
    • generate_password() A nifty function that generates random passwords based on a word file ($CFG->wordlist)
    • err() A function to print out an error market (<<) if an error variable is defined
    • username_exists() Returns true if the username exists
    • email_exists() Returns true if the email address exists
    • reset_user_password() A function that resets the user's password and sends them an email notification
    {mospagebreak title=Step 4: New Administrative Screens}

    Now that we've got login and privileges in place, we can put some protection on our administrative pages. If you look at the administrative pages:

    • admin/index.php
    • admin/categories.php
    • admin/products.php
    • admin/users.php

    You will see two new commands at the top of the file: require_login() and require_priv(). The first function makes sure the user has logged in (if not, it will present the login screen) and the latter function makes sure the user has the required privileges.

    The file admin/users.php is a new administrative screen that lets you (the administrator) create, edit, and remove users. It is built like the other maintenance screens, so look at the source code for details.

    The file admin/categories.php has been modified so that it presents the list of parent categories in a bigger list box, like the one in products.php. This doesn't really have anything to do with user management, but I thought it would be a nice change to make :)

    The file admin/products.php has been modified, the build_category_tree function was taken from here and placed into the shared lib/mymarket.php file. All our shared functions that are specific to MyMarket will be kept in lib/mymarket.php.

    More PHP Articles
    More By Ying Zhang


     

       

    PHP ARTICLES

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway