PHP
  Home arrow PHP arrow Page 4 - User Authentication with patUser (part 1)
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

User Authentication with patUser (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 15
    2003-04-23


    Table of Contents:
  • User Authentication with patUser (part 1)
  • Power User
  • Dump Truck
  • Zone Six
  • Breaking It Down
  • A Different Realm
  • Icing On The Cake

  • 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


    User Authentication with patUser (part 1) - Zone Six
    (Page 4 of 7 )

    I'll begin with something simple - using patUser to restrict access to a Web page. In this scenario, only users who provide appropriate credentials - a login name and password - will be allowed access to the page; all other users will simply be presented with an error message.

    Here's the code:

    <?php // include classes include("../include/patDbc.php"); include("../include/patUser.php"); include("../include/patTemplate.php"); // initialize database layer $db = new patMySqlDbc("localhost", "db111", "us111", "secret"); // initialize template engine $tmpl = new patTemplate(); $tmpl->setBasedir("../templates"); // initialize patUser $u = new patUser(true); // connect patUser to database/template engines $u->setAuthDbc($db); $u->setTemplate($tmpl); // check credentials before displaying page $uid = $u->requireAuthentication("displayLogin"); // restricted page goes here ?> <html> <head> <basefont face="Arial"> </head> <body> <center> <h2>Welcome to Zone 6!</h2> <u>This is a restricted zone. Trespassers will be vaporized.</u> </center> <p align="right"> Your user ID is <?=$uid?> <br> <a href="logout.php">Log out</a> </body> </html>
    As you can see, the script above contains an HTML page which I'm assuming you want to restrict access to, surrounded with some fairly complicated code. The code is all explained a little further down, so don't worry too much about it just yet; instead, try accessing this page through your Web browser.

    You should see something like this:



    Try entering a random user name and password - since the database is currently empty, the system should barf and throw you back out with an error message.



    Now, add a user to the "users" table,

    INSERT INTO users (`uid`, `username`, `passwd`) VALUES ('', 'joe', 'joe');
    and try logging in again with that username and password. This time, patUser should recognize that your credentials are valid and allow you access to the page.



     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Implementing the Iterator SPL Interface
    - Building a Data Access Layer for the Data Ma...
    - Building a Singleton Database with Restricti...
    - Working with Reflected Properties with the R...
    - The Iterator, Countable and ArrayAccess SPL ...
    - Implementing the Data Mapper Design Pattern ...
    - Defining an Abstract Class with Restrictive ...
    - The Reflection API: Working with Reflected M...
    - Using Restrictive Constructors in PHP 5
    - Getting Information on a Reflected Class wit...
    - Introducing the Reflection API in PHP 5
    - Swift Mailer's Batchsend Method and Other Fe...
    - Embedding Attachments into Email Messages wi...
    - Dynamically Attaching Files with Swift Mailer
    - Using Different Paths for Attachments with S...


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code

     



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