在php3中是没有session这类东东的,但咱们又需求,怎样办呢?别急,有良多人替你做了这些,这个中最着名的要算phplib了。你可以去国外下载,可以上国际大局部php站点下载。咱们要做的第一件事是让phplib和php3联合在一同使它能任务。为了能完成这方面的功效,咱们需求先装置phplib。随着我来做,很轻易的(以下办法在win2000+php3.0.16+apache1.3.12+phplib7.2c+mysql3.23.21 for win32 上经由过程)phplib最根基的功效包含用户认证,Session办理,权限及数据库的笼统化。
if (!isset($_PHPLIB) or !is_array($_PHPLIB)) {
$_PHPLIB["libdir"] = "d:/apache/php/"; //这儿改成你放phplib下php目次的途径
}
然后将d:/apache/php/local.inc文件改以下:
class DB_Example extends DB_Sql {
var $Host = "localhost";//你的mysql数据库地点主机名
var $Database = "test";//数据库名
var $User = "root";//数据库用户名
var $Password = "";//数据库用户口令
}
[Session]
session.save_handler = files ; handler used to store/retrieve data(用甚么保留session变量,默许情形下用文件)
session.save_path = c:/temp ; argument passed to save_handler(保留session变量的目次,在linux/unix下为/tmp,在win下设为你的目次)
; in the case of files, this is the
; path where data files are stored
session.use_cookies = 1 ; whether to use cookies(是不是利用cookies,固然,在win下别无选择)
session.name = PHPSESSID
; name of the session(默许session利用的cookies名,建议不要修改)
; is used as cookie name
session.auto_start = 0 ; initialize session on request startup(是不是主动启用session,当为1时,在每页中就能够不用挪用session_start()函数了)
session.cookie_lifetime = 0 ; lifetime in seconds of cookie(设定 cookie 送到阅读器后的保留工夫,单元为秒。缺省值为 0,暗示直到阅读器封闭。)
; or if 0, until browser is restarted
session.cookie_path = / ; the path the cookie is valid for(cookie)(cookies无效途径)
session.cookie_domain = ; the domain the cookie is valid for(cookies无效域名)
session.serialize_handler = php ; handler used to serialize data(界说序列化数据的标识,本功效只要 WDDX 模块或 PHP 外部利用。缺省值为 php)
; php is the standard serializer of PHP
session.gc_probability = 1 ; percentual probability that the (设定每次一时文件入手下手处置 (gc, garbage collection) 处置几率。缺省值为 1。 )
; 'garbage collection' process is started
; on every session initialization
session.gc_maxlifetime = 1440 ; after this number of seconds, stored(设定保留session的一时文件被排除前的存活秒数)
; data will be seen as 'garbage' and
; cleaned up by the gc process
session.referer_check = ; check HTTP Referer to invalidate (决意参照到客户真个Session 代码是不是要删除。有时在平安或其它思索时,会设定不删除。缺省值为 0。)
; externally stored URLs containing ids
session.entropy_length = 0 ; how many bytes to read from the file(设定 session 从高熵值资本读取的位数。缺省值为 0.)
session.entropy_file = ; specified here to create the session id(设定 session 代码创立时,利用内部高熵值资本或文件来创立,例如 UNIX 体系上的 /dev/random 或 /dev/urandom。 )
; session.entropy_length = 16
; session.entropy_file = /dev/urandom
session.cache_limiter = nocache ; set to { nocache,private,public } to (设定session缓冲限制)
; determine HTTP caching aspects
session.cache_expire = 180 ; document expires after n minutes(文档无效期,单元为分钟)
(很抱愧,因为版权缘由,我不克不及把以下代码中的英文去失落,只好加些正文了
==================================================================================
<?
/* ------------------------------------------------------------------------
* session_mysql.php
* ------------------------------------------------------------------------
* PHP4 MySQL Session Handler
* Version 1.00
* by Ying Zhang (ying@zippydesign.com)
* Last Modified: May 21 2000
*
* ------------------------------------------------------------------------
* TERMS OF USAGE:
* ------------------------------------------------------------------------
* You are free to use this library in any way you want, no warranties are
* expressed or implied. This works for me, but I don't guarantee that it
* works for you, USE AT YOUR OWN RISK.
*
* While not required to do so, I would appreciate it if you would retain
* this header information. If you make any modifications or improvements,
* please send them via email to Ying Zhang <ying@zippydesign.com>.
*
* ------------------------------------------------------------------------
* DESCRIPTION:
* ------------------------------------------------------------------------
* This library tells the PHP4 session handler to write to a MySQL database
* instead of creating individual files for each session.
*
* Create a new database in MySQL called "sessions" like so:
*
* CREATE TABLE sessions (
* sesskey char(32) not null,
* expiry int(11) unsigned not null,
* value text not null,
* PRIMARY KEY (sesskey)
* );
*
* ------------------------------------------------------------------------
* INSTALLATION:
* ------------------------------------------------------------------------
* Make sure you have MySQL support compiled into PHP4. Then copy this
* script to a directory that is accessible by the rest of your PHP
* scripts.
* 确信你的php4有mysql撑持,然后把这个剧本拷贝到和你的php剧本有关的目次。
* ------------------------------------------------------------------------
* USAGE:(利用办法)
* ------------------------------------------------------------------------
* Include this file in your scripts before you call session_start(), you
* don't have to do anything special after that.
* 包括这个文件到你要利用session的文件中,必需在挪用session_start()之前,不然,
* 会很惨的,不要怪我没告知你。 如许就不需求再做甚么任务了,还和你之前用session的办法一样。
*/
$SESS_DBHOST = "localhost"; /* database server hostname */
$SESS_DBNAME = "sessions"; /* database name */
$SESS_DBUSER = "phpsession"; /* database user */
$SESS_DBPASS = "phpsession"; /* database password */
if (! $qid) {
$qry = "UPDATE sessions SET expiry = $expiry, value = '$value' WHERE sesskey
= '$key' AND expiry > " . time();
$qid = mysql_query($qry, $SESS_DBH);
}
return $qid;
}
function sess_destroy($key) {
global $SESS_DBH;
$qry = "DELETE FROM sessions WHERE sesskey = '$key'";
$qid = mysql_query($qry, $SESS_DBH);
return $qid;
}
function sess_gc($maxlifetime) {
global $SESS_DBH;
$qry = "DELETE FROM sessions WHERE expiry < " . time();
$qid = mysql_query($qry, $SESS_DBH);
return mysql_affected_rows($SESS_DBH);
}
session_set_save_handler(
"sess_open",
"sess_close",
"sess_read",
"sess_write",
"sess_destroy",
"sess_gc");
?>
=================================================================
定制利用dbm文件时的接口
=================================================================
<?
/* ------------------------------------------------------------------------
* session_dbm.php
* ------------------------------------------------------------------------
* PHP4 DBM Session Handler
* Version 1.00
* by Ying Zhang (ying@zippydesign.com)
* Last Modified: May 21 2000
*
* ------------------------------------------------------------------------
* TERMS OF USAGE:
* ------------------------------------------------------------------------
* You are free to use this library in any way you want, no warranties are
* expressed or implied. This works for me, but I don't guarantee that it
* works for you, USE AT YOUR OWN RISK.
*
* While not required to do so, I would appreciate it if you would retain
* this header information. If you make any modifications or improvements,
* please send them via email to Ying Zhang <ying@zippydesign.com>.
*
* ------------------------------------------------------------------------
* DESCRIPTION:
* ------------------------------------------------------------------------
* This library tells the PHP4 session handler to write to a DBM file
* instead of creating individual files for each session.
*
* ------------------------------------------------------------------------
* INSTALLATION:
* ------------------------------------------------------------------------
* Make sure you have DBM support compiled into PHP4. Then copy this
* script to a directory that is accessible by the rest of your PHP
* scripts.
* 确信你的php4有DBM撑持。拷贝这个文件在你的php剧本目次。
* ------------------------------------------------------------------------
* USAGE:
* ------------------------------------------------------------------------
* Include this file in your scripts before you call session_start(), you
* don't have to do anything special after that.
* 在挪用session_start()之前请包括这个文件。以后就不需求作甚么任务了。
*/