[Phplib-commit] CVS: php-lib-stable/php session.inc,1.8,1.9
Brought to you by:
nhruby,
richardarcher
|
From: Richard A. <ric...@us...> - 2001-08-18 02:45:49
|
Update of /cvsroot/phplib/php-lib-stable/php
In directory usw-pr-cvs1:/tmp/cvs-serv32753
Modified Files:
session.inc
Log Message:
renamed $prefix in serialize to $var
changes to comments and whitespace
syncing devel and stable trees
Index: session.inc
===================================================================
RCS file: /cvsroot/phplib/php-lib-stable/php/session.inc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** session.inc 2001/08/12 05:24:44 1.8
--- session.inc 2001/08/18 02:45:47 1.9
***************
*** 8,12 ****
* $Id$
*
! */
class Session {
--- 8,12 ----
* $Id$
*
! */
class Session {
***************
*** 31,35 ****
## page_close() guaranteed.
! var $allowcache = "no"; ## "passive", "no", "private", "public"
var $allowcache_expire = 1440; ## If you allowcache, data expires in this
## many minutes.
--- 31,35 ----
## page_close() guaranteed.
! var $allowcache = "no"; ## "passive", "no", "private" or "public"
var $allowcache_expire = 1440; ## If you allowcache, data expires in this
## many minutes.
***************
*** 88,94 ****
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $QUERY_STRING;
$newid=true;
!
$this->name = $this->cookiename==""?$this->classname:$this->cookiename;
!
if ( "" == $id ) {
$newid=false;
--- 88,94 ----
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $QUERY_STRING;
$newid=true;
!
$this->name = $this->cookiename==""?$this->classname:$this->cookiename;
!
if ( "" == $id ) {
$newid=false;
***************
*** 99,103 ****
break;
case "cookie":
! $id = isset($HTTP_COOKIE_VARS[$this->name]) ? $HTTP_COOKIE_VARS[$this->name] : "";
break;
default:
--- 99,104 ----
break;
case "cookie":
! $id = isset($HTTP_COOKIE_VARS[$this->name]) ?
! $HTTP_COOKIE_VARS[$this->name] : "";
break;
default:
***************
*** 106,115 ****
}
}
!
if ( "" == $id ) {
$newid=true;
$id = $this->that->ac_newid(md5(uniqid($this->magic)), $this->name);
}
!
switch ($this->mode) {
case "cookie":
--- 107,116 ----
}
}
!
if ( "" == $id ) {
$newid=true;
$id = $this->that->ac_newid(md5(uniqid($this->magic)), $this->name);
}
!
switch ($this->mode) {
case "cookie":
***************
*** 132,157 ****
break;
}
-
$this->id = $id;
}
## put_id():
! ##
## Stop using the current session id (unset cookie, ...) and
## abandon a session.
function put_id() {
global $HTTP_COOKIE_VARS;
!
$this->name = $this->cookiename==""?$this->classname:$this->cookiename;
!
switch ($this->mode) {
case "inline":
die("This has not been coded yet.");
break;
!
case "get":
die("This has not been coded yet.");
break;
!
default:
SetCookie($this->name, "", 0, "/", $this->cookie_domain);
--- 133,157 ----
break;
}
$this->id = $id;
}
## put_id():
! ##
## Stop using the current session id (unset cookie, ...) and
## abandon a session.
function put_id() {
global $HTTP_COOKIE_VARS;
!
$this->name = $this->cookiename==""?$this->classname:$this->cookiename;
!
switch ($this->mode) {
case "inline":
die("This has not been coded yet.");
break;
!
case "get":
die("This has not been coded yet.");
break;
!
default:
SetCookie($this->name, "", 0, "/", $this->cookie_domain);
***************
*** 164,168 ****
##
## Delete the current session record and put the session id.
!
function delete() {
$this->that->ac_delete($this->id, $this->name);
--- 164,168 ----
##
## Delete the current session record and put the session id.
!
function delete() {
$this->that->ac_delete($this->id, $this->name);
***************
*** 172,187 ****
## url($url):
##
! ## Helper function: returns $url concatenated with the current
## session $id.
!
! function url($url){
$url=ereg_replace("[&?]+$", "", $url);
!
switch ($this->mode) {
case "get":
-
$url .= ( strpos($url, "?") != false ? "&" : "?" ).
urlencode($this->name)."=".$this->id;
-
break;
default:
--- 172,185 ----
## url($url):
##
! ## Helper function: returns $url concatenated with the current
## session $id.
!
! function url($url) {
$url=ereg_replace("[&?]+$", "", $url);
!
switch ($this->mode) {
case "get":
$url .= ( strpos($url, "?") != false ? "&" : "?" ).
urlencode($this->name)."=".$this->id;
break;
default:
***************
*** 206,210 ****
print $this->self_url();
}
!
function hidden_session()
{
--- 204,208 ----
print $this->self_url();
}
!
function hidden_session()
{
***************
*** 217,221 ****
if ((isset($QUERY_STRING) && ("" != $QUERY_STRING))
! || ($this->mode == "get")) {
$sep_char = "&";
} else {
--- 215,219 ----
if ((isset($QUERY_STRING) && ("" != $QUERY_STRING))
! || ($this->mode == "get")) {
$sep_char = "&";
} else {
***************
*** 236,242 ****
}
! ## serialize($prefix,&$str):
##
! ## appends a serialized representation of $$prefix
## at the end of $str.
##
--- 234,240 ----
}
! ## serialize($var,&$str):
##
! ## appends a serialized representation of $$var
## at the end of $str.
##
***************
*** 245,285 ****
## and a variable $persistent_slots (containing the names of the slots
## to be saved as an array of strings).
! ##
! ## You don't need to know...
! function serialize($prefix, $str) {
static $t,$l,$k;
! ## Determine the type of $$prefix
! eval("\$t = gettype(\$$prefix);");
switch ( $t ) {
case "array":
! ## $$prefix is an array. Enumerate the elements and serialize them.
! eval("reset(\$$prefix); \$l = gettype(list(\$k)=each(\$$prefix));");
! $str .= "\$$prefix = array(); ";
while ( "array" == $l ) {
## Structural recursion
! $this->serialize($prefix."['".ereg_replace("([\\'])", "\\\\1", $k)."']", &$str);
! eval("\$l = gettype(list(\$k)=each(\$$prefix));");
}
break;
case "object":
! ## $$prefix is an object. Enumerate the slots and serialize them.
! eval("\$k = \$${prefix}->classname; \$l = reset(\$${prefix}->persistent_slots);");
! $str.="\$$prefix = new $k; ";
while ( $l ) {
## Structural recursion.
! $this->serialize($prefix."->".$l,&$str);
! eval("\$l = next(\$${prefix}->persistent_slots);");
}
break;
default:
! ## $$prefix is an atom. Extract it to $l, then generate code.
! eval("\$l = \$$prefix;");
! $str.="\$$prefix = '".ereg_replace("([\\'])", "\\\\1", $l)."'; ";
!
!
break;
}
--- 243,280 ----
## and a variable $persistent_slots (containing the names of the slots
## to be saved as an array of strings).
!
! function serialize($var, $str) {
static $t,$l,$k;
! ## Determine the type of $$var
! eval("\$t = gettype(\$$var);");
switch ( $t ) {
case "array":
! ## $$var is an array. Enumerate the elements and serialize them.
! eval("reset(\$$var); \$l = gettype(list(\$k)=each(\$$var));");
! $str .= "\$$var = array(); ";
while ( "array" == $l ) {
## Structural recursion
! $this->serialize($var."['".ereg_replace("([\\'])", "\\\\1", $k)."']", &$str);
! eval("\$l = gettype(list(\$k)=each(\$$var));");
}
break;
case "object":
! ## $$var is an object. Enumerate the slots and serialize them.
! eval("\$k = \$${var}->classname; \$l = reset(\$${var}->persistent_slots);");
! $str.="\$$var = new $k; ";
while ( $l ) {
## Structural recursion.
! $this->serialize($var."->".$l,&$str);
! eval("\$l = next(\$${var}->persistent_slots);");
}
break;
default:
! ## $$var is an atom. Extract it to $l, then generate code.
! eval("\$l = \$$var;");
! $str.="\$$var = '".ereg_replace("([\\'])", "\\\\1", $l)."'; ";
break;
}
***************
*** 312,319 ****
}
}
!
$r = $this->that->ac_store($this->id, $this->name, $str);
$this->release_lock();
! if(!$r) $this->that->ac_halt("Session: freeze() failed.");
}
--- 307,315 ----
}
}
!
$r = $this->that->ac_store($this->id, $this->name, $str);
$this->release_lock();
!
! if (!$r) $this->that->ac_halt("Session: freeze() failed.");
}
***************
*** 326,330 ****
$vals = $this->that->ac_get_value($this->id, $this->name);
-
eval(sprintf(";%s",$vals));
}
--- 322,325 ----
***************
*** 370,374 ****
##
! function set_container(){
$name = $this->that_class;
$this->that = new $name;
--- 365,369 ----
##
! function set_container() {
$name = $this->that_class;
$this->that = new $name;
***************
*** 377,401 ****
}
! function set_tokenname(){
$this->name = $this->cookiename==""?$this->classname:$this->cookiename;
}
! function release_token(){
! global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_HOST, $HTTPS;
! if ( isset($this->fallback_mode)
! && ( "get" == $this->fallback_mode )
! && ( "cookie" == $this->mode )
! && ( ! isset($HTTP_COOKIE_VARS[$this->name]) ) ) {
! if ( isset($HTTP_GET_VARS[$this->name]) ) {
$this->mode = $this->fallback_mode;
} else {
header("Status: 302 Moved Temporarily");
! if(!isset($sid)){
! $sid='';
! }
$this->get_id($sid);
! $this->mode = $this->fallback_mode;
! if( isset($HTTPS) && $HTTPS == 'on' ){
! ## You will need to fix suexec as well, if you use Apache and CGI PHP
$PROTOCOL='https';
} else {
--- 372,411 ----
}
! function set_tokenname() {
$this->name = $this->cookiename==""?$this->classname:$this->cookiename;
}
! function release_token() {
! global $HTTP_COOKIE_VARS, $HTTP_GET_VARS,
! $HTTP_HOST, $HTTPS;
!
! if ( isset($this->fallback_mode)
! && ("get" == $this->fallback_mode)
! && ("cookie" == $this->mode)
! && (! isset($HTTP_COOKIE_VARS[$this->name])) ) {
!
! // Looks like no cookie here - check GET params
! if (isset($HTTP_GET_VARS[$this->name])) {
! // Session info passed via GET - go to fallback_mode
$this->mode = $this->fallback_mode;
} else {
+ // It seems to be the first load of this page -
+ // no cookie and no GET params
+
header("Status: 302 Moved Temporarily");
!
! if (!isset($sid)) {
! $sid='';
! }
!
! // Generate session ID and setup cookie.
$this->get_id($sid);
!
! // Next line is to generate correct self_url() later
! $this->mode = $this->fallback_mode;
!
! if ( isset($HTTPS) && $HTTPS == 'on' ) {
! ## You will need to fix suexec as well, if you
! ## use Apache and CGI PHP
$PROTOCOL='https';
} else {
***************
*** 406,410 ****
}
}
! }
function put_headers() {
--- 416,420 ----
}
}
! }
function put_headers() {
***************
*** 414,418 ****
# Note that in HTTP/1.1 the Cache-Control headers override the Expires
# headers and HTTP/1.0 ignores headers it does not recognize (e.g,
! # Cache-Control). Mulitple Cache-Control directives are split into
# mulitple headers to better support MSIE 4.x.
#
--- 424,428 ----
# Note that in HTTP/1.1 the Cache-Control headers override the Expires
# headers and HTTP/1.0 ignores headers it does not recognize (e.g,
! # Cache-Control). Mulitple Cache-Control directives are split into
# mulitple headers to better support MSIE 4.x.
#
***************
*** 423,427 ****
case "passive":
! $mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT";
header("Last-Modified: " . $mod_gmt);
# possibly ie5 needs the pre-check line. This needs testing.
--- 433,437 ----
case "passive":
! $mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT";
header("Last-Modified: " . $mod_gmt);
# possibly ie5 needs the pre-check line. This needs testing.
***************
*** 431,435 ****
case "public":
$exp_gmt = gmdate("D, d M Y H:i:s", time() + $this->allowcache_expire * 60) . " GMT";
! $mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT";
header("Expires: " . $exp_gmt);
header("Last-Modified: " . $mod_gmt);
--- 441,445 ----
case "public":
$exp_gmt = gmdate("D, d M Y H:i:s", time() + $this->allowcache_expire * 60) . " GMT";
! $mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT";
header("Expires: " . $exp_gmt);
header("Last-Modified: " . $mod_gmt);
***************
*** 437,441 ****
header("Cache-Control: max-age=" . $this->allowcache_expire * 60);
break;
!
case "private":
$mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT";
--- 447,451 ----
header("Cache-Control: max-age=" . $this->allowcache_expire * 60);
break;
!
case "private":
$mod_gmt = gmdate("D, d M Y H:i:s", getlastmod()) . " GMT";
***************
*** 469,473 ****
}
-
##
## Initialization
--- 479,482 ----
***************
*** 476,480 ****
function start($sid = "") {
$this->set_container();
! $this->set_tokenname();
$this->release_token($sid);
$this->put_headers();
--- 485,489 ----
function start($sid = "") {
$this->set_container();
! $this->set_tokenname();
$this->release_token($sid);
$this->put_headers();
|