HTTP as a protocol is stateless, which doesn't make it easy for a developer. For example, your web server sends out a page to someone ordering from an online shop, and then forgets all about it. A few seconds later, the same person sends another request, ordering another item. As far as the web server is concerned, it could be an entirely different person. So to make sure the right orders are associated with the right person, a developer has to employ some sneaky tricks. Before PHP4, you could have used something like PHPLIB for session management. But PHP4 comes with a complete set of sessioning functions. This article explains how to use them.
This step-by-step guide presents a free cut-and-paste example code of a username and password login web based system. Developed using PHP, MySQL and JavaScript.
Updated to include improved security
(PHP HTTP_POST_VARS).
Platform(s): Linux, Windows, FreeBSD, Mac OSX, Sun Solaris
This tutorial teaches you to initiate user authentication using PHP, and then to authenticate users by matching the value of the global variables $PHP_AUTH_USER, and $PHP_AUTH_PW to a list of valid usernames and passwords. The sample code included with this tutorial will show you how to use either hard-coded values, a flat file, an existing .htpasswd file or a database table to manage your valid usernames and passwords. This tutorial is intended for the PHP programmer who is generally familiar with authentication, but who would be interested in learning a practical method for authenticating access to one or more Web site pages.
One cool thing about php is that you can fairly easily validate users before displaying content on a page by page basis. Let's say you don't want to restrict the entire directory using htaccess, this is a neat alternative. This tutorial shows how to create a simple page-based login system using PHP and mySQL.
One of the new great features with PHP4 is the session management feature. It allows you to store variables in a session 'object' during a user visit. This article discusses what a session and a session variable are, and what it can do.
This is a short tutorial on how to use the sessions (in PHP4) with a user, form-based login. This would be useful for just about any site where you had a "members only" area and wanted to validate the users from a database or anything else. The examples used authorize off of a MySQL database on the same server.
This comprehensive 8-page online tutorial explains how to authenticate and track users with PHP. Main topics include: HTTP Authentication with PHP, Validation Against a Flat File, Authenticate Against a Database, Using Cookies, and Sessions and User Preferences.
This tutorial along with sample code explains how to make a hardcoded admin password gateway using PHP. It also covers how to use .htaccess for server side password protection.
This three-page online tutorial/article talks about managing user session and authntication using PHPLIB, a set of PHP classes designed to make is easier to develop web based PHP applications.