Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Session Management and Authentication with PHPLIB
Let's face it, web pages aren't designed for interaction with users. At one time or another, you've probably found yourself needing to know what user you are dealing with, and some information about that user. But how do you do it on the web? There are many ways, but most of them are either error prone, or serious security risks. Passing around form data from page to page can easily be sniffed, and even more easily forged. What is a webmaster to do?
The simple answer is PHPLIB. PHPLIB is a set of PHP classes that are designed to make is easier to develop web based applications - things that need interaction. This is provided by many classes, the most essential being authentication, session management, permissions, and database abstraction.
What You'll Need
To use phplib, you need php installed on your server. Unlike basic authentication, phplib works with either the cgi or the module. You will probably need at least version 3.0.5 of php. Earlier cgi versions may work if you compiled them with --enable-foce-cgi-redirect option. Otherwise, you will get nothing but security errors. PHP also needs to be configured with track_vars enabled. You will also need a database. PHPLIB currently supports MySQL, Orace, ODBC, PostgreSQL, and Sybase.
How it Works
First and foremost, the classes need to be configured for your system. The only file that has to be modified is the local.inc file included in the distribution. It is filled in with a sample setup which can be used almost as is, or can be modified as you want. Before setting it up though, it's a good idea to understand what is going on.
Each page that uses PHPLIB must first import all of the needed files. You can do this with php's auto_prepend feature if you have access to your php.ini and you want the files included on EVERY page. If not, you can specify an include directory in the php.ini, or just use the absolute path to require the PHPLIB files. A sample file called prepend.php3 is included in the distribution, which can be required at the top of each file to include all of the other needed files.
At the top of each phplib page, you must make a call to the page_open function. This initializes the features that you plan on using, more on this later. A typical page_open call that gives authentication, session, and permission capabilities looks like:

<?php

page_open
(array("sess" => "Cms_Session", "auth" => "Cms_Auth", "perm" => "Cms_Perm"));

?>
The keys of the array (sess, auth, perm) are the variable names you will use to address the objects, and must be the standard variable names phplib uses (sess, auth, perm...). The values are the names of the classes you create in your local.inc. The page_open call must be before any output to the browser, and you only need to put in the features that you are going to use (if you're not using authentication on the page, just leave that part out). The script must end with a call to the page_close() function, which writes all changes back to the database. If you forget the page_close() call, you may find some things not working quite as expected...
Because phplib uses cookies to store information, your page_open() call must be issued before ANY output is sent to the browser. Output can be anything from html to blank lines. If you find yourself getting errors which say something along the lines of "Oops - SetCookie called after header has been sent" this means that there was some output before the page_open was called. The typical culprits, and the hardest to find, are blank lines outside of the <? and ?> tags in the included files. Check your local.inc or prepend.php3 for blank lines at the end with vi, or another editor which will show you these.
Next Page


Comments:
RE: The specified procedure could not be foundchristo09/26/05 06:25
RE: How to use session control in php4 ?xcore09/15/05 22:40
SESSION - PHP WIN-XPARI POLINSKY03/04/05 21:30
php session erroryuhtwe12/29/04 02:56
RE: session variables not workingtmal512/12/04 10:20
RE: WRONG!!!!Robin Percy12/04/04 04:07
RE: session variables not workingvarna12/02/04 00:04
RE: Can't get values of session variablesbenji12/18/02 01:26
RE: how to pass variables in to other filesmetador12/12/02 15:06
session managementravi10/02/02 03:38
session variables not workingkiran09/19/02 03:48
Can't get values of session variablesToberius09/01/02 17:16
RE: Cannot get session variableWasif Zaidi of Pakistan08/23/02 00:22
RE: how to pass variables in to other filesWasif08/22/02 05:04
RE: how to pass variables in to other filesGreg08/20/02 08:19
RE: PHP Session variablesGreg08/20/02 08:15
PHP4 session securityBowie07/15/02 22:08
RE: PHP Session variablesKass07/13/02 05:11
how to pass variables in to other filessamant07/12/02 12:24
RE: PHP Session variablessamant07/12/02 12:22
RE: Cannot get session variablejhun05/09/02 00:31
Cannot get session variableMelody04/16/02 22:08
phplib configurationJarry04/12/02 17:04
phpib, help me pleaseJarry04/12/02 16:58
sessionShriya04/10/02 06:40
RE: PHP Session variableskandarp bhatt03/27/02 04:24
WhoIsOnline with PHPLibtc7703/06/02 07:37
Import to PostgreSQLRadek02/28/02 17:55
RE: getting warning message in sessionmontino02/22/02 08:32
WRONG!!!mcq01/31/02 21:02
getting warning message in sessionTuan01/22/02 12:53
RE: php sesson errorUttam12/24/01 21:22
RE: no sessions workingamitabh12/24/01 03:52
php sesson errorPagla12/19/01 15:17
PHP Session variablesBalaji12/19/01 00:47
Use of phplib authentication - browser closeJohn Lodge12/13/01 15:16
RE: How to detect Browser name using PHP?Cameron Green11/13/01 21:32
How to detect Browser name using PHP?Hitesh Patel10/23/01 06:16
The specified procedure could not be foundSunder Rajendran10/22/01 15:36
Sniffing/ PHPLIB SecurityCameron Green10/04/01 04:06
GET is overiding CookieDaniel09/12/01 06:17
RE: PHP Session variables and scalabiltyDouglas Forrest07/08/01 18:05
RE: not working with GETJim Henderson06/03/01 19:22
PHP Session variables and scalabiltyScot Braze05/24/01 08:33
Problem with PHPLIB sessions....Ekku05/21/01 04:09
RE: not working with GETVivek04/25/01 08:51
More details........GEP04/20/01 00:59
How to use session control in php4 ?Arm04/17/01 03:36
spellchecksomeone03/30/01 09:12
GET uses CookiesLars Vagt03/25/01 18:08
RE: not working with GETRichard Church02/09/01 14:00
ThanksLouis Zezeran12/03/00 00:21
PHPLib SlaveryAnderson Fortaleza11/21/00 11:07
Starting out....james maina08/22/00 13:15
this actually works..stephane schmit08/22/00 03:43
RE: not working with GETstephane schmit08/17/00 10:05
not working with GETDaan07/24/00 12:44
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.