PHP
  Home arrow PHP arrow Page 7 - Building an E-Commerce Site Part 2: Managing Users with Sessions
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Building an E-Commerce Site Part 2: Managing Users with Sessions
By: Ying Zhang
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 31
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek