1999-12-12 22:22:55 +08:00
|
|
|
/*
|
1999-06-06 03:52:58 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-06-06 03:52:58 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 14:11:02 +08:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-06-06 03:52:58 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-06-06 03:52:58 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-07-10 18:09:15 +08:00
|
|
|
| Authors: Sascha Schumann <sascha@schumann.cx> |
|
1999-10-01 22:54:55 +08:00
|
|
|
| Andrei Zmievski <andrei@ispi.net> |
|
1999-06-06 03:52:58 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
#include "php.h"
|
|
|
|
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
1999-06-07 03:53:59 +08:00
|
|
|
#include "win32/time.h"
|
2000-02-11 21:41:30 +08:00
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
1999-06-07 02:22:17 +08:00
|
|
|
#endif
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-12-12 22:16:55 +08:00
|
|
|
#include <sys/stat.h>
|
1999-09-12 01:20:31 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
1999-06-06 03:52:58 +08:00
|
|
|
#include "php_ini.h"
|
|
|
|
#include "SAPI.h"
|
|
|
|
#include "php_session.h"
|
1999-06-07 03:53:59 +08:00
|
|
|
#include "ext/standard/md5.h"
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "ext/standard/php_var.h"
|
1999-06-29 23:39:59 +08:00
|
|
|
#include "ext/standard/datetime.h"
|
1999-09-01 22:20:15 +08:00
|
|
|
#include "ext/standard/php_lcg.h"
|
2000-09-20 09:22:55 +08:00
|
|
|
#include "ext/standard/url_scanner_ex.h"
|
2000-03-29 17:36:27 +08:00
|
|
|
#include "ext/standard/php_output.h"
|
1999-12-19 07:28:43 +08:00
|
|
|
#include "ext/standard/php_rand.h" /* for RAND_MAX */
|
2000-04-07 05:07:44 +08:00
|
|
|
#include "ext/standard/info.h"
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
#include "ext/standard/php_smart_str.h"
|
|
|
|
|
2001-05-03 23:48:49 +08:00
|
|
|
#include "mod_files.h"
|
|
|
|
#include "mod_user.h"
|
|
|
|
|
1999-06-06 03:52:58 +08:00
|
|
|
function_entry session_functions[] = {
|
|
|
|
PHP_FE(session_name, NULL)
|
|
|
|
PHP_FE(session_module_name, NULL)
|
|
|
|
PHP_FE(session_save_path, NULL)
|
|
|
|
PHP_FE(session_id, NULL)
|
|
|
|
PHP_FE(session_decode, NULL)
|
|
|
|
PHP_FE(session_register, NULL)
|
|
|
|
PHP_FE(session_unregister, NULL)
|
1999-06-28 23:46:56 +08:00
|
|
|
PHP_FE(session_is_registered, NULL)
|
1999-06-06 23:18:51 +08:00
|
|
|
PHP_FE(session_encode, NULL)
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FE(session_start, NULL)
|
1999-06-08 00:43:24 +08:00
|
|
|
PHP_FE(session_destroy, NULL)
|
1999-09-12 06:31:04 +08:00
|
|
|
PHP_FE(session_unset, NULL)
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_FE(session_set_save_handler, NULL)
|
2000-09-01 23:56:26 +08:00
|
|
|
PHP_FE(session_cache_limiter, NULL)
|
|
|
|
PHP_FE(session_set_cookie_params, NULL)
|
2000-03-31 02:50:09 +08:00
|
|
|
PHP_FE(session_get_cookie_params, NULL)
|
2000-10-12 03:47:15 +08:00
|
|
|
PHP_FE(session_write_close, NULL)
|
1999-06-06 03:52:58 +08:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
int ps_globals_id;
|
|
|
|
#else
|
|
|
|
php_ps_globals ps_globals;
|
|
|
|
#endif
|
|
|
|
|
2000-05-26 21:02:11 +08:00
|
|
|
static ps_module *_php_find_ps_module(char *name PSLS_DC);
|
|
|
|
static const ps_serializer *_php_find_ps_serializer(char *name PSLS_DC);
|
|
|
|
|
|
|
|
static PHP_INI_MH(OnUpdateSaveHandler)
|
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
PS(mod) = _php_find_ps_module(new_value PSLS_CC);
|
2000-07-03 00:27:39 +08:00
|
|
|
if(!PS(mod)) {
|
2000-07-28 00:43:38 +08:00
|
|
|
php_error(E_ERROR,"Cannot find save handler %s",new_value);
|
2000-07-03 00:27:39 +08:00
|
|
|
}
|
2000-05-26 21:02:11 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PHP_INI_MH(OnUpdateSerializer)
|
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
PS(serializer) = _php_find_ps_serializer(new_value PSLS_CC);
|
2000-07-03 00:27:39 +08:00
|
|
|
if(!PS(serializer)) {
|
2000-07-28 00:43:38 +08:00
|
|
|
php_error(E_ERROR,"Cannot find serialization handler %s",new_value);
|
2000-07-03 00:27:39 +08:00
|
|
|
}
|
2000-05-26 21:02:11 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_INI_BEGIN()
|
2000-09-06 08:50:01 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.save_path", "/tmp", PHP_INI_ALL, OnUpdateString, save_path, php_ps_globals, ps_globals)
|
|
|
|
STD_PHP_INI_ENTRY("session.name", "PHPSESSID", PHP_INI_ALL, OnUpdateString, session_name, php_ps_globals, ps_globals)
|
2000-05-26 21:02:11 +08:00
|
|
|
PHP_INI_ENTRY("session.save_handler", "files", PHP_INI_ALL, OnUpdateSaveHandler)
|
2000-05-26 19:12:49 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("session.auto_start", "0", PHP_INI_ALL, OnUpdateBool, auto_start, php_ps_globals, ps_globals)
|
|
|
|
STD_PHP_INI_ENTRY("session.gc_probability", "1", PHP_INI_ALL, OnUpdateInt, gc_probability, php_ps_globals, ps_globals)
|
|
|
|
STD_PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, OnUpdateInt, gc_maxlifetime, php_ps_globals, ps_globals)
|
2000-06-09 08:26:56 +08:00
|
|
|
PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, OnUpdateSerializer)
|
2000-05-26 19:12:49 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.cookie_lifetime", "0", PHP_INI_ALL, OnUpdateInt, cookie_lifetime, php_ps_globals, ps_globals)
|
2000-09-06 08:50:01 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.cookie_path", "/", PHP_INI_ALL, OnUpdateString, cookie_path, php_ps_globals, ps_globals)
|
|
|
|
STD_PHP_INI_ENTRY("session.cookie_domain", "", PHP_INI_ALL, OnUpdateString, cookie_domain, php_ps_globals, ps_globals)
|
2000-10-29 01:13:28 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("session.cookie_secure", "", PHP_INI_ALL, OnUpdateBool, cookie_secure, php_ps_globals, ps_globals)
|
2000-05-26 19:12:49 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("session.use_cookies", "1", PHP_INI_ALL, OnUpdateBool, use_cookies, php_ps_globals, ps_globals)
|
2000-09-06 08:50:01 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateString, extern_referer_chk, php_ps_globals, ps_globals)
|
|
|
|
STD_PHP_INI_ENTRY("session.entropy_file", "", PHP_INI_ALL, OnUpdateString, entropy_file, php_ps_globals, ps_globals)
|
2000-05-26 19:12:49 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.entropy_length", "0", PHP_INI_ALL, OnUpdateInt, entropy_length, php_ps_globals, ps_globals)
|
2000-09-06 08:50:01 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache", PHP_INI_ALL, OnUpdateString, cache_limiter, php_ps_globals, ps_globals)
|
2000-05-26 19:12:49 +08:00
|
|
|
STD_PHP_INI_ENTRY("session.cache_expire", "180", PHP_INI_ALL, OnUpdateInt, cache_expire, php_ps_globals, ps_globals)
|
1999-12-05 01:02:04 +08:00
|
|
|
/* Commented out until future discussion */
|
|
|
|
/* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_INI_END()
|
|
|
|
|
1999-07-01 13:45:48 +08:00
|
|
|
PS_SERIALIZER_FUNCS(php);
|
2000-09-01 23:24:58 +08:00
|
|
|
PS_SERIALIZER_FUNCS(php_binary);
|
1999-07-01 13:45:48 +08:00
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
#define MAX_SERIALIZERS 10
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
static ps_serializer ps_serializers[MAX_SERIALIZERS + 1] = {
|
1999-07-01 13:45:48 +08:00
|
|
|
PS_SERIALIZER_ENTRY(php),
|
2001-05-02 01:01:51 +08:00
|
|
|
PS_SERIALIZER_ENTRY(php_binary)
|
1999-07-01 13:45:48 +08:00
|
|
|
};
|
1999-06-07 03:53:59 +08:00
|
|
|
|
2001-05-03 23:48:49 +08:00
|
|
|
#define MAX_MODULES 10
|
|
|
|
|
|
|
|
static ps_module *ps_modules[MAX_MODULES + 1] = {
|
|
|
|
ps_files_ptr,
|
|
|
|
ps_user_ptr
|
|
|
|
};
|
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
int php_session_register_serializer(const char *name,
|
|
|
|
int (*encode)(PS_SERIALIZER_ENCODE_ARGS),
|
|
|
|
int (*decode)(PS_SERIALIZER_DECODE_ARGS))
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_SERIALIZERS; i++) {
|
|
|
|
if (ps_serializers[i].name == NULL) {
|
|
|
|
ps_serializers[i].name = name;
|
|
|
|
ps_serializers[i].encode = encode;
|
|
|
|
ps_serializers[i].decode = decode;
|
|
|
|
ps_serializers[i + 1].name = NULL;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-05-03 23:48:49 +08:00
|
|
|
int php_session_register_module(ps_module *ptr)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODULES; i++) {
|
|
|
|
if (!ps_modules[i]) {
|
|
|
|
ps_modules[i] = ptr;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2001-05-02 01:01:51 +08:00
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MINIT_FUNCTION(session);
|
|
|
|
PHP_RINIT_FUNCTION(session);
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(session);
|
2000-01-17 05:03:49 +08:00
|
|
|
PHP_RSHUTDOWN_FUNCTION(session);
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MINFO_FUNCTION(session);
|
|
|
|
|
1999-09-12 06:31:04 +08:00
|
|
|
static void php_rinit_session_globals(PSLS_D);
|
1999-06-11 17:23:00 +08:00
|
|
|
static void php_rshutdown_session_globals(PSLS_D);
|
2000-09-06 22:16:12 +08:00
|
|
|
static zend_bool php_session_destroy(PSLS_D);
|
1999-06-06 03:52:58 +08:00
|
|
|
|
|
|
|
zend_module_entry session_module_entry = {
|
2000-03-07 02:44:01 +08:00
|
|
|
"session",
|
1999-06-06 03:52:58 +08:00
|
|
|
session_functions,
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MINIT(session), PHP_MSHUTDOWN(session),
|
2000-01-17 05:03:49 +08:00
|
|
|
PHP_RINIT(session), PHP_RSHUTDOWN(session),
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MINFO(session),
|
2000-03-10 16:34:13 +08:00
|
|
|
STANDARD_MODULE_PROPERTIES
|
1999-06-06 03:52:58 +08:00
|
|
|
};
|
|
|
|
|
2000-05-23 17:33:51 +08:00
|
|
|
#ifdef COMPILE_DL_SESSION
|
2000-05-02 08:30:36 +08:00
|
|
|
ZEND_GET_MODULE(session)
|
2000-05-01 10:42:55 +08:00
|
|
|
#endif
|
|
|
|
|
1999-12-12 22:16:55 +08:00
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
void (*func)(PSLS_D);
|
2000-09-06 22:16:12 +08:00
|
|
|
} php_session_cache_limiter_t;
|
1999-12-12 22:16:55 +08:00
|
|
|
|
2000-03-28 06:40:49 +08:00
|
|
|
#define CACHE_LIMITER_FUNC(name) static void _php_cache_limiter_##name(PSLS_D)
|
1999-12-12 22:16:55 +08:00
|
|
|
#define CACHE_LIMITER(name) { #name, _php_cache_limiter_##name },
|
|
|
|
|
2000-04-28 21:03:13 +08:00
|
|
|
#define ADD_COOKIE(a) sapi_add_header(a, strlen(a), 1);
|
1999-12-12 22:16:55 +08:00
|
|
|
|
1999-06-06 03:52:58 +08:00
|
|
|
#define STR_CAT(P,S,I) {\
|
|
|
|
pval *__p = (P);\
|
2000-09-01 23:24:58 +08:00
|
|
|
size_t __l = (I);\
|
2000-09-27 23:24:09 +08:00
|
|
|
ulong __i = Z_STRLEN_P(__p);\
|
|
|
|
Z_STRLEN_P(__p) += __l;\
|
|
|
|
Z_STRVAL_P(__p) = (char *)erealloc(Z_STRVAL_P(__p), Z_STRLEN_P(__p) + 1);\
|
2000-09-06 22:13:31 +08:00
|
|
|
memcpy(Z_STRVAL_P(__p) + __i, (S), __l); \
|
|
|
|
Z_STRVAL_P(__p)[Z_STRLEN_P(__p)] = '\0'; \
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_STR 512
|
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
void php_set_session_var(char *name, size_t namelen, zval *state_val PSLS_DC)
|
1999-12-05 01:02:04 +08:00
|
|
|
{
|
|
|
|
zval *state_val_copy;
|
|
|
|
PLS_FETCH();
|
|
|
|
ELS_FETCH();
|
1999-11-30 07:07:20 +08:00
|
|
|
|
1999-12-27 05:21:33 +08:00
|
|
|
ALLOC_ZVAL(state_val_copy);
|
1999-12-05 01:02:04 +08:00
|
|
|
*state_val_copy = *state_val;
|
|
|
|
zval_copy_ctor(state_val_copy);
|
1999-12-05 02:56:17 +08:00
|
|
|
state_val_copy->refcount = 0;
|
1999-12-05 01:02:04 +08:00
|
|
|
|
2000-09-06 03:06:29 +08:00
|
|
|
if (PG(register_globals)) {
|
2000-11-19 21:13:36 +08:00
|
|
|
zval **old_symbol;
|
2000-11-20 20:39:14 +08:00
|
|
|
if(zend_hash_find(&EG(symbol_table),name,namelen+1,(void *)&old_symbol) == SUCCESS) {
|
2000-11-19 21:13:36 +08:00
|
|
|
/*
|
|
|
|
There where old one, we need to replace it accurately.
|
|
|
|
hash_update in zend_set_hash_symbol is not good, because
|
|
|
|
it will leave referenced variables (such as local instances
|
|
|
|
of a global variable) dangling.
|
|
|
|
*/
|
2000-11-20 20:39:14 +08:00
|
|
|
|
|
|
|
REPLACE_ZVAL_VALUE(old_symbol,state_val_copy,0);
|
2000-11-19 21:13:36 +08:00
|
|
|
FREE_ZVAL(state_val_copy);
|
|
|
|
|
2001-05-23 01:55:07 +08:00
|
|
|
zend_set_hash_symbol(*old_symbol, name, namelen, 1, 1, Z_ARRVAL_P(PS(http_session_vars)));
|
2000-11-19 21:13:36 +08:00
|
|
|
} else {
|
2001-05-23 01:55:07 +08:00
|
|
|
zend_set_hash_symbol(state_val_copy, name, namelen, 1, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table));
|
1999-12-05 01:02:04 +08:00
|
|
|
}
|
2000-11-19 21:13:36 +08:00
|
|
|
} else {
|
2000-09-06 22:25:47 +08:00
|
|
|
zend_set_hash_symbol(state_val_copy, name, namelen, 0, 1, Z_ARRVAL_P(PS(http_session_vars)));
|
1999-12-05 01:02:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
int php_get_session_var(char *name, size_t namelen, zval ***state_var PLS_DC PSLS_DC ELS_DC)
|
1999-12-05 01:02:04 +08:00
|
|
|
{
|
2000-03-06 22:36:11 +08:00
|
|
|
HashTable *ht = &EG(symbol_table);
|
|
|
|
|
2000-09-06 03:06:29 +08:00
|
|
|
if (!PG(register_globals))
|
2000-09-06 22:25:47 +08:00
|
|
|
ht = Z_ARRVAL_P(PS(http_session_vars));
|
2000-03-06 22:36:11 +08:00
|
|
|
|
|
|
|
return zend_hash_find(ht, name, namelen + 1, (void **)state_var);
|
1999-12-05 01:02:04 +08:00
|
|
|
}
|
1999-11-30 07:07:20 +08:00
|
|
|
|
2000-09-01 23:24:58 +08:00
|
|
|
#define PS_BIN_NR_OF_BITS 8
|
|
|
|
#define PS_BIN_UNDEF (1<<(PS_BIN_NR_OF_BITS-1))
|
|
|
|
#define PS_BIN_MAX (PS_BIN_UNDEF-1)
|
|
|
|
|
|
|
|
PS_SERIALIZER_ENCODE_FUNC(php_binary)
|
|
|
|
{
|
|
|
|
zval *buf;
|
2001-05-13 15:37:28 +08:00
|
|
|
unsigned char strbuf[MAX_STR + 1];
|
2000-10-31 01:10:06 +08:00
|
|
|
php_serialize_data_t var_hash;
|
2001-05-02 01:01:51 +08:00
|
|
|
PS_ENCODE_VARS;
|
2000-09-01 23:24:58 +08:00
|
|
|
|
|
|
|
buf = ecalloc(sizeof(*buf), 1);
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_P(buf) = IS_STRING;
|
2000-09-01 23:24:58 +08:00
|
|
|
buf->refcount++;
|
|
|
|
|
2000-10-31 01:10:06 +08:00
|
|
|
PHP_VAR_SERIALIZE_INIT(var_hash);
|
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
PS_ENCODE_LOOP(
|
2001-04-26 10:54:27 +08:00
|
|
|
if (key_length > PS_BIN_MAX) continue;
|
2001-05-13 15:37:28 +08:00
|
|
|
strbuf[0] = (unsigned char) key_length;
|
2001-04-26 10:54:27 +08:00
|
|
|
memcpy(strbuf + 1, key, key_length);
|
2000-09-01 23:24:58 +08:00
|
|
|
|
2001-04-26 10:54:27 +08:00
|
|
|
STR_CAT(buf, strbuf, key_length + 1);
|
2000-10-31 01:10:06 +08:00
|
|
|
php_var_serialize(buf, struc, &var_hash);
|
2000-09-01 23:24:58 +08:00
|
|
|
} else {
|
2001-04-26 10:54:27 +08:00
|
|
|
if (key_length > PS_BIN_MAX) continue;
|
2001-05-13 15:37:28 +08:00
|
|
|
strbuf[0] = (unsigned char) key_length & PS_BIN_UNDEF;
|
2001-04-26 10:54:27 +08:00
|
|
|
memcpy(strbuf + 1, key, key_length);
|
2000-09-01 23:24:58 +08:00
|
|
|
|
2001-04-26 10:54:27 +08:00
|
|
|
STR_CAT(buf, strbuf, key_length + 1);
|
2000-09-01 23:24:58 +08:00
|
|
|
);
|
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
if (newlen) *newlen = Z_STRLEN_P(buf);
|
|
|
|
*newstr = Z_STRVAL_P(buf);
|
2000-09-01 23:24:58 +08:00
|
|
|
efree(buf);
|
2000-10-31 01:10:06 +08:00
|
|
|
PHP_VAR_SERIALIZE_DESTROY(var_hash);
|
2000-09-01 23:24:58 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_SERIALIZER_DECODE_FUNC(php_binary)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
char *name;
|
|
|
|
const char *endptr = val + vallen;
|
|
|
|
zval *current;
|
|
|
|
int namelen;
|
|
|
|
int has_value;
|
2000-10-31 01:10:06 +08:00
|
|
|
php_serialize_data_t var_hash;
|
|
|
|
|
|
|
|
PHP_VAR_UNSERIALIZE_INIT(var_hash);
|
2000-09-01 23:24:58 +08:00
|
|
|
|
2001-01-07 18:42:15 +08:00
|
|
|
MAKE_STD_ZVAL(current);
|
2000-09-01 23:24:58 +08:00
|
|
|
for (p = val; p < endptr; ) {
|
|
|
|
namelen = *p & (~PS_BIN_UNDEF);
|
|
|
|
has_value = *p & PS_BIN_UNDEF ? 0 : 1;
|
|
|
|
|
|
|
|
name = estrndup(p + 1, namelen);
|
|
|
|
|
|
|
|
p += namelen + 1;
|
|
|
|
|
|
|
|
if (has_value) {
|
2000-10-31 01:10:06 +08:00
|
|
|
if (php_var_unserialize(¤t, &p, endptr, &var_hash)) {
|
2000-09-01 23:24:58 +08:00
|
|
|
php_set_session_var(name, namelen, current PSLS_CC);
|
|
|
|
zval_dtor(current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PS_ADD_VARL(name, namelen);
|
|
|
|
efree(name);
|
|
|
|
}
|
2001-01-07 18:42:15 +08:00
|
|
|
FREE_ZVAL(current);
|
2000-10-31 01:10:06 +08:00
|
|
|
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
|
2000-09-01 23:24:58 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PS_DELIMITER '|'
|
|
|
|
#define PS_UNDEF_MARKER '!'
|
|
|
|
|
1999-07-01 13:45:48 +08:00
|
|
|
PS_SERIALIZER_ENCODE_FUNC(php)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
1999-12-05 01:02:04 +08:00
|
|
|
zval *buf;
|
1999-06-06 03:52:58 +08:00
|
|
|
char strbuf[MAX_STR + 1];
|
2000-10-31 01:10:06 +08:00
|
|
|
php_serialize_data_t var_hash;
|
2001-05-02 01:01:51 +08:00
|
|
|
PS_ENCODE_VARS;
|
1999-06-06 03:52:58 +08:00
|
|
|
|
|
|
|
buf = ecalloc(sizeof(*buf), 1);
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_P(buf) = IS_STRING;
|
1999-06-06 03:52:58 +08:00
|
|
|
buf->refcount++;
|
|
|
|
|
2000-10-31 01:10:06 +08:00
|
|
|
PHP_VAR_SERIALIZE_INIT(var_hash);
|
|
|
|
|
2001-05-02 01:01:51 +08:00
|
|
|
PS_ENCODE_LOOP(
|
2001-04-26 10:54:27 +08:00
|
|
|
if (key_length + 1 > MAX_STR) continue;
|
|
|
|
memcpy(strbuf, key, key_length);
|
|
|
|
strbuf[key_length] = PS_DELIMITER;
|
|
|
|
STR_CAT(buf, strbuf, key_length + 1);
|
2000-09-01 23:24:58 +08:00
|
|
|
|
2000-10-31 01:10:06 +08:00
|
|
|
php_var_serialize(buf, struc, &var_hash);
|
1999-06-06 03:52:58 +08:00
|
|
|
} else {
|
2001-04-26 10:54:27 +08:00
|
|
|
if (key_length + 2 > MAX_STR) continue;
|
2000-09-01 23:24:58 +08:00
|
|
|
strbuf[0] = PS_UNDEF_MARKER;
|
2001-04-26 10:54:27 +08:00
|
|
|
memcpy(strbuf + 1, key, key_length);
|
|
|
|
strbuf[key_length + 1] = PS_DELIMITER;
|
2000-09-01 23:24:58 +08:00
|
|
|
|
2001-04-26 10:54:27 +08:00
|
|
|
STR_CAT(buf, strbuf, key_length + 2);
|
1999-11-30 07:07:20 +08:00
|
|
|
);
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
if (newlen) *newlen = Z_STRLEN_P(buf);
|
|
|
|
*newstr = Z_STRVAL_P(buf);
|
1999-06-06 03:52:58 +08:00
|
|
|
efree(buf);
|
|
|
|
|
2000-10-31 01:10:06 +08:00
|
|
|
PHP_VAR_SERIALIZE_DESTROY(var_hash);
|
1999-07-01 13:45:48 +08:00
|
|
|
return SUCCESS;
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
1999-07-01 13:45:48 +08:00
|
|
|
PS_SERIALIZER_DECODE_FUNC(php)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
1999-07-01 13:45:48 +08:00
|
|
|
const char *p, *q;
|
1999-06-06 03:52:58 +08:00
|
|
|
char *name;
|
1999-07-01 13:45:48 +08:00
|
|
|
const char *endptr = val + vallen;
|
1999-12-05 01:02:04 +08:00
|
|
|
zval *current;
|
1999-06-06 03:52:58 +08:00
|
|
|
int namelen;
|
|
|
|
int has_value;
|
2000-10-31 01:10:06 +08:00
|
|
|
php_serialize_data_t var_hash;
|
|
|
|
|
|
|
|
PHP_VAR_UNSERIALIZE_INIT(var_hash);
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2001-01-07 18:42:15 +08:00
|
|
|
MAKE_STD_ZVAL(current);
|
2000-09-01 23:24:58 +08:00
|
|
|
for (p = q = val; (p < endptr) && (q = memchr(p, PS_DELIMITER, endptr - p)); p = q) {
|
|
|
|
if (p[0] == PS_UNDEF_MARKER) {
|
1999-06-06 03:52:58 +08:00
|
|
|
p++;
|
|
|
|
has_value = 0;
|
1999-09-16 23:35:49 +08:00
|
|
|
} else {
|
1999-06-06 03:52:58 +08:00
|
|
|
has_value = 1;
|
1999-09-16 23:35:49 +08:00
|
|
|
}
|
1999-06-06 03:52:58 +08:00
|
|
|
|
|
|
|
namelen = q - p;
|
1999-06-08 00:43:24 +08:00
|
|
|
name = estrndup(p, namelen);
|
1999-06-06 03:52:58 +08:00
|
|
|
q++;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (has_value) {
|
2000-10-31 01:10:06 +08:00
|
|
|
if (php_var_unserialize(¤t, &q, endptr, &var_hash)) {
|
1999-12-05 01:02:04 +08:00
|
|
|
php_set_session_var(name, namelen, current PSLS_CC);
|
|
|
|
zval_dtor(current);
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
}
|
2000-09-01 23:24:58 +08:00
|
|
|
PS_ADD_VARL(name, namelen);
|
1999-06-06 03:52:58 +08:00
|
|
|
efree(name);
|
|
|
|
}
|
2001-01-07 18:42:15 +08:00
|
|
|
FREE_ZVAL(current);
|
1999-07-01 13:45:48 +08:00
|
|
|
|
2000-10-31 01:10:06 +08:00
|
|
|
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
|
1999-07-01 13:45:48 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-12-05 18:29:06 +08:00
|
|
|
static void php_session_track_init(void)
|
1999-12-05 01:02:04 +08:00
|
|
|
{
|
2000-06-29 21:09:27 +08:00
|
|
|
zval **old_vars = NULL;
|
1999-12-05 01:02:04 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
ELS_FETCH();
|
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
if (zend_hash_find(&EG(symbol_table), "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"), (void **)&old_vars) == SUCCESS && Z_TYPE_PP(old_vars) == IS_ARRAY) {
|
2000-06-29 21:09:27 +08:00
|
|
|
PS(http_session_vars) = *old_vars;
|
2000-09-06 22:25:47 +08:00
|
|
|
zend_hash_clean(Z_ARRVAL_P(PS(http_session_vars)));
|
2000-06-29 21:09:27 +08:00
|
|
|
} else {
|
|
|
|
if(old_vars) {
|
|
|
|
zend_hash_del(&EG(symbol_table), "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"));
|
|
|
|
}
|
|
|
|
MAKE_STD_ZVAL(PS(http_session_vars));
|
|
|
|
array_init(PS(http_session_vars));
|
|
|
|
ZEND_SET_GLOBAL_VAR_WITH_LENGTH("HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"), PS(http_session_vars), 1, 0);
|
|
|
|
}
|
1999-12-05 01:02:04 +08:00
|
|
|
}
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static char *php_session_encode(int *newlen PSLS_DC)
|
1999-07-01 13:45:48 +08:00
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (PS(serializer)->encode(&ret, newlen PSLS_CC) == FAILURE)
|
1999-09-16 20:00:58 +08:00
|
|
|
ret = NULL;
|
1999-07-01 13:45:48 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static void php_session_decode(const char *val, int vallen PSLS_DC)
|
1999-07-01 13:45:48 +08:00
|
|
|
{
|
2000-09-06 03:06:29 +08:00
|
|
|
php_session_track_init();
|
2000-06-09 08:23:20 +08:00
|
|
|
if (PS(serializer)->decode(val, vallen PSLS_CC) == FAILURE) {
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_destroy(PSLS_C);
|
2000-07-28 00:43:38 +08:00
|
|
|
php_error(E_WARNING, "Failed to decode session object. Session has been destroyed.");
|
2000-06-09 08:23:20 +08:00
|
|
|
}
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
2001-05-19 17:58:31 +08:00
|
|
|
static char hexconvtab[] = "0123456789abcdef";
|
|
|
|
|
1999-09-12 01:20:31 +08:00
|
|
|
static char *_php_create_id(int *newlen PSLS_DC)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
2000-02-26 11:20:55 +08:00
|
|
|
PHP_MD5_CTX context;
|
1999-06-06 03:52:58 +08:00
|
|
|
unsigned char digest[16];
|
|
|
|
char buf[256];
|
|
|
|
struct timeval tv;
|
|
|
|
int i;
|
2001-05-19 17:58:31 +08:00
|
|
|
int j = 0;
|
|
|
|
unsigned char c;
|
1999-06-06 03:52:58 +08:00
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
2000-02-26 11:20:55 +08:00
|
|
|
PHP_MD5Init(&context);
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-08-22 04:48:40 +08:00
|
|
|
sprintf(buf, "%ld%ld%0.8f", tv.tv_sec, tv.tv_usec, php_combined_lcg() * 10);
|
2000-02-26 11:20:55 +08:00
|
|
|
PHP_MD5Update(&context, buf, strlen(buf));
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(entropy_length) > 0) {
|
1999-09-12 01:20:31 +08:00
|
|
|
int fd;
|
|
|
|
|
2001-04-30 20:45:02 +08:00
|
|
|
fd = VCWD_OPEN((PS(entropy_file), O_RDONLY));
|
2000-02-11 20:59:08 +08:00
|
|
|
if (fd >= 0) {
|
2001-05-19 17:58:31 +08:00
|
|
|
char buf[2048];
|
1999-09-12 01:20:31 +08:00
|
|
|
int n;
|
2001-05-19 17:58:31 +08:00
|
|
|
int to_read = PS(entropy_length);
|
1999-09-12 01:20:31 +08:00
|
|
|
|
2001-05-19 17:58:31 +08:00
|
|
|
while (to_read > 0) {
|
|
|
|
n = read(fd, buf, MIN(to_read, sizeof(buf)));
|
|
|
|
if (n <= 0) break;
|
|
|
|
PHP_MD5Update(&context, buf, n);
|
|
|
|
to_read -= n;
|
1999-09-12 01:20:31 +08:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-26 11:20:55 +08:00
|
|
|
PHP_MD5Final(digest, &context);
|
2001-05-19 17:58:31 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
c = digest[i];
|
|
|
|
buf[j++] = hexconvtab[c >> 4];
|
|
|
|
buf[j++] = hexconvtab[c & 15];
|
|
|
|
}
|
|
|
|
buf[j] = '\0';
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (newlen)
|
2001-05-19 17:58:31 +08:00
|
|
|
*newlen = j;
|
1999-06-06 03:52:58 +08:00
|
|
|
return estrdup(buf);
|
|
|
|
}
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static void php_session_initialize(PSLS_D)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
|
|
|
char *val;
|
|
|
|
int vallen;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(mod)->open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) {
|
2000-02-22 22:44:29 +08:00
|
|
|
php_error(E_ERROR, "Failed to initialize session module");
|
1999-06-06 03:52:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(mod)->read(&PS(mod_data), PS(id), &val, &vallen) == SUCCESS) {
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_decode(val, vallen PSLS_CC);
|
1999-06-06 03:52:58 +08:00
|
|
|
efree(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static void php_session_save_current_state(PSLS_D)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
|
|
|
char *val;
|
|
|
|
int vallen;
|
2000-11-22 12:10:04 +08:00
|
|
|
int ret = FAILURE;
|
2000-03-08 22:57:26 +08:00
|
|
|
char *variable;
|
|
|
|
ulong num_key;
|
|
|
|
PLS_FETCH();
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-03-08 22:57:26 +08:00
|
|
|
if (!PG(register_globals)) {
|
2000-11-22 12:10:04 +08:00
|
|
|
if (!PS(http_session_vars)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-07-09 18:31:47 +08:00
|
|
|
|
2000-11-22 12:10:04 +08:00
|
|
|
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(PS(http_session_vars)));
|
2000-12-22 20:57:09 +08:00
|
|
|
zend_hash_get_current_key(Z_ARRVAL_P(PS(http_session_vars)), &variable, &num_key, 1) == HASH_KEY_IS_STRING;
|
2000-11-22 12:10:04 +08:00
|
|
|
zend_hash_move_forward(Z_ARRVAL_P(PS(http_session_vars)))) {
|
|
|
|
PS_ADD_VAR(variable);
|
|
|
|
}
|
2000-03-08 22:57:26 +08:00
|
|
|
}
|
|
|
|
|
2000-10-23 21:10:01 +08:00
|
|
|
if (PS(mod_data)) {
|
|
|
|
val = php_session_encode(&vallen PSLS_CC);
|
|
|
|
if (val) {
|
|
|
|
ret = PS(mod)->write(&PS(mod_data), PS(id), val, vallen);
|
|
|
|
efree(val);
|
|
|
|
} else {
|
|
|
|
ret = PS(mod)->write(&PS(mod_data), PS(id), "", 0);
|
|
|
|
}
|
|
|
|
}
|
2000-02-22 22:44:29 +08:00
|
|
|
|
|
|
|
if (ret == FAILURE)
|
2000-07-10 16:35:03 +08:00
|
|
|
php_error(E_WARNING, "Failed to write session data (%s). Please "
|
|
|
|
"verify that the current setting of session.save_path "
|
|
|
|
"is correct (%s)",
|
|
|
|
PS(mod)->name,
|
2000-02-22 22:44:29 +08:00
|
|
|
PS(save_path));
|
|
|
|
|
2000-07-10 16:35:03 +08:00
|
|
|
|
2000-10-23 21:10:01 +08:00
|
|
|
if (PS(mod_data))
|
|
|
|
PS(mod)->close(&PS(mod_data));
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
1999-12-12 22:16:55 +08:00
|
|
|
static char *month_names[] = {
|
1999-12-12 22:22:55 +08:00
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
1999-12-12 22:16:55 +08:00
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
|
|
};
|
|
|
|
|
1999-12-12 22:22:55 +08:00
|
|
|
static char *week_days[] = {
|
1999-12-12 22:16:55 +08:00
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
|
|
|
|
};
|
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
static void strcpy_gmt(char *ubuf, time_t *when)
|
1999-12-12 22:16:55 +08:00
|
|
|
{
|
|
|
|
char buf[MAX_STR];
|
|
|
|
struct tm tm;
|
2001-03-14 00:53:34 +08:00
|
|
|
int n;
|
1999-12-12 22:16:55 +08:00
|
|
|
|
2000-05-04 18:38:17 +08:00
|
|
|
php_gmtime_r(when, &tm);
|
1999-12-12 22:16:55 +08:00
|
|
|
|
|
|
|
/* we know all components, thus it is safe to use sprintf */
|
2001-03-14 00:53:34 +08:00
|
|
|
n = sprintf(buf, "%s, %d %s %d %02d:%02d:%02d GMT", week_days[tm.tm_wday], tm.tm_mday, month_names[tm.tm_mon], tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
memcpy(ubuf, buf, n);
|
|
|
|
ubuf[n] = '\0';
|
1999-12-12 22:16:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void last_modified(void)
|
|
|
|
{
|
2000-11-02 23:47:02 +08:00
|
|
|
const char *path;
|
1999-12-12 22:16:55 +08:00
|
|
|
struct stat sb;
|
|
|
|
char buf[MAX_STR + 1];
|
|
|
|
SLS_FETCH();
|
|
|
|
|
|
|
|
path = SG(request_info).path_translated;
|
|
|
|
if (path) {
|
2001-04-30 20:45:02 +08:00
|
|
|
if (VCWD_STAT(path, &sb) == -1) {
|
1999-12-12 22:16:55 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
#define LAST_MODIFIED "Last-Modified: "
|
|
|
|
memcpy(buf, LAST_MODIFIED, sizeof(LAST_MODIFIED) - 1);
|
|
|
|
strcpy_gmt(buf + sizeof(LAST_MODIFIED) - 1, &sb.st_mtime);
|
1999-12-12 22:16:55 +08:00
|
|
|
ADD_COOKIE(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_LIMITER_FUNC(public)
|
|
|
|
{
|
|
|
|
char buf[MAX_STR + 1];
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
time(&now);
|
|
|
|
now += PS(cache_expire) * 60;
|
2001-03-14 00:53:34 +08:00
|
|
|
#define EXPIRES "Expires: "
|
|
|
|
memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1);
|
|
|
|
strcpy_gmt(buf + sizeof(EXPIRES) - 1, &now);
|
1999-12-12 22:16:55 +08:00
|
|
|
ADD_COOKIE(buf);
|
|
|
|
|
2000-06-09 07:42:04 +08:00
|
|
|
sprintf(buf, "Cache-Control: public, max-age=%ld", PS(cache_expire) * 60);
|
1999-12-12 22:16:55 +08:00
|
|
|
ADD_COOKIE(buf);
|
|
|
|
|
|
|
|
last_modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_LIMITER_FUNC(private)
|
|
|
|
{
|
|
|
|
char buf[MAX_STR + 1];
|
|
|
|
|
|
|
|
ADD_COOKIE("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
|
2000-06-09 07:42:04 +08:00
|
|
|
sprintf(buf, "Cache-Control: private, max-age=%ld, pre-check=%ld", PS(cache_expire) * 60, PS(cache_expire) * 60);
|
1999-12-12 22:16:55 +08:00
|
|
|
ADD_COOKIE(buf);
|
|
|
|
|
|
|
|
last_modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_LIMITER_FUNC(nocache)
|
|
|
|
{
|
|
|
|
ADD_COOKIE("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
|
2000-03-26 08:43:56 +08:00
|
|
|
/* For HTTP/1.1 conforming clients and the rest (MSIE 5) */
|
2000-09-01 23:56:26 +08:00
|
|
|
ADD_COOKIE("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
|
1999-12-12 22:16:55 +08:00
|
|
|
/* For HTTP/1.0 conforming clients */
|
|
|
|
ADD_COOKIE("Pragma: no-cache");
|
|
|
|
}
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static php_session_cache_limiter_t php_session_cache_limiters[] = {
|
1999-12-12 22:16:55 +08:00
|
|
|
CACHE_LIMITER(public)
|
|
|
|
CACHE_LIMITER(private)
|
|
|
|
CACHE_LIMITER(nocache)
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static int php_session_cache_limiter(PSLS_D)
|
1999-12-12 22:16:55 +08:00
|
|
|
{
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_cache_limiter_t *lim;
|
2000-01-16 00:56:30 +08:00
|
|
|
SLS_FETCH();
|
1999-12-12 22:16:55 +08:00
|
|
|
|
2000-01-15 21:20:39 +08:00
|
|
|
if (SG(headers_sent)) {
|
2000-03-29 17:36:27 +08:00
|
|
|
char *output_start_filename = php_get_output_start_filename();
|
|
|
|
int output_start_lineno = php_get_output_start_lineno();
|
|
|
|
|
|
|
|
if (output_start_filename) {
|
2000-08-11 03:27:30 +08:00
|
|
|
php_error(E_WARNING, "Cannot send session cache limiter - headers already sent (output started at %s:%d)",
|
2000-03-29 17:36:27 +08:00
|
|
|
output_start_filename, output_start_lineno);
|
|
|
|
} else {
|
|
|
|
php_error(E_WARNING, "Cannot send session cache limiter - headers already sent");
|
|
|
|
}
|
2000-09-01 23:56:26 +08:00
|
|
|
return (-2);
|
2000-01-15 21:20:39 +08:00
|
|
|
}
|
|
|
|
|
1999-12-12 22:16:55 +08:00
|
|
|
for (lim = php_session_cache_limiters; lim->name; lim++) {
|
|
|
|
if (!strcasecmp(lim->name, PS(cache_limiter))) {
|
|
|
|
lim->func(PSLS_C);
|
2000-09-01 23:56:26 +08:00
|
|
|
return (0);
|
1999-12-12 22:16:55 +08:00
|
|
|
}
|
|
|
|
}
|
2000-09-01 23:56:26 +08:00
|
|
|
|
|
|
|
return (-1);
|
1999-12-12 22:16:55 +08:00
|
|
|
}
|
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
#define COOKIE_SET_COOKIE "Set-Cookie: "
|
1999-06-29 23:39:59 +08:00
|
|
|
#define COOKIE_EXPIRES "; expires="
|
1999-10-31 21:26:40 +08:00
|
|
|
#define COOKIE_PATH "; path="
|
|
|
|
#define COOKIE_DOMAIN "; domain="
|
2000-10-29 01:13:28 +08:00
|
|
|
#define COOKIE_SECURE "; secure"
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static void php_session_send_cookie(PSLS_D)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
2001-03-14 00:53:34 +08:00
|
|
|
smart_str ncookie = {0};
|
1999-06-29 23:39:59 +08:00
|
|
|
char *date_fmt = NULL;
|
2000-01-16 00:56:30 +08:00
|
|
|
SLS_FETCH();
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-01-15 21:20:39 +08:00
|
|
|
if (SG(headers_sent)) {
|
2000-03-29 17:36:27 +08:00
|
|
|
char *output_start_filename = php_get_output_start_filename();
|
|
|
|
int output_start_lineno = php_get_output_start_lineno();
|
|
|
|
|
|
|
|
if (output_start_filename) {
|
|
|
|
php_error(E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)",
|
|
|
|
output_start_filename, output_start_lineno);
|
|
|
|
} else {
|
|
|
|
php_error(E_WARNING, "Cannot send session cookie - headers already sent");
|
|
|
|
}
|
2000-01-15 21:20:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
smart_str_appends(&ncookie, COOKIE_SET_COOKIE);
|
|
|
|
smart_str_appends(&ncookie, PS(session_name));
|
|
|
|
smart_str_appendc(&ncookie, '=');
|
|
|
|
smart_str_appends(&ncookie, PS(id));
|
|
|
|
|
1999-10-31 21:26:40 +08:00
|
|
|
if (PS(cookie_lifetime) > 0) {
|
1999-12-18 12:01:20 +08:00
|
|
|
date_fmt = php_std_date(time(NULL) + PS(cookie_lifetime));
|
2001-03-14 00:53:34 +08:00
|
|
|
|
|
|
|
smart_str_appends(&ncookie, COOKIE_EXPIRES);
|
|
|
|
smart_str_appends(&ncookie, date_fmt);
|
|
|
|
efree(date_fmt);
|
2000-10-29 01:13:28 +08:00
|
|
|
}
|
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
if (PS(cookie_path)[0]) {
|
|
|
|
smart_str_appends(&ncookie, COOKIE_PATH);
|
|
|
|
smart_str_appends(&ncookie, PS(cookie_path));
|
1999-06-29 23:39:59 +08:00
|
|
|
}
|
1999-10-31 21:26:40 +08:00
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
if (PS(cookie_domain)[0]) {
|
|
|
|
smart_str_appends(&ncookie, COOKIE_DOMAIN);
|
|
|
|
smart_str_appends(&ncookie, PS(cookie_domain));
|
1999-10-31 21:26:40 +08:00
|
|
|
}
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-10-29 01:13:28 +08:00
|
|
|
if (PS(cookie_secure)) {
|
2001-03-14 00:53:34 +08:00
|
|
|
smart_str_appends(&ncookie, COOKIE_SECURE);
|
2000-10-29 01:13:28 +08:00
|
|
|
}
|
|
|
|
|
2001-03-14 00:53:34 +08:00
|
|
|
smart_str_0(&ncookie);
|
|
|
|
|
|
|
|
sapi_add_header(ncookie.c, ncookie.len, 0);
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
1999-06-07 03:25:39 +08:00
|
|
|
static ps_module *_php_find_ps_module(char *name PSLS_DC)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
|
|
|
ps_module *ret = NULL;
|
|
|
|
ps_module **mod;
|
2001-05-03 23:48:49 +08:00
|
|
|
int i;
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2001-05-03 23:48:49 +08:00
|
|
|
for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++)
|
2000-02-11 20:59:08 +08:00
|
|
|
if (*mod && !strcasecmp(name, (*mod)->name)) {
|
1999-06-06 03:52:58 +08:00
|
|
|
ret = *mod;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1999-07-01 13:45:48 +08:00
|
|
|
static const ps_serializer *_php_find_ps_serializer(char *name PSLS_DC)
|
|
|
|
{
|
|
|
|
const ps_serializer *ret = NULL;
|
|
|
|
const ps_serializer *mod;
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
for (mod = ps_serializers; mod->name; mod++)
|
2000-02-11 20:59:08 +08:00
|
|
|
if (!strcasecmp(name, mod->name)) {
|
1999-07-01 13:45:48 +08:00
|
|
|
ret = mod;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1999-12-22 08:38:04 +08:00
|
|
|
#define PPID2SID \
|
|
|
|
convert_to_string((*ppid)); \
|
2000-09-06 22:13:31 +08:00
|
|
|
PS(id) = estrndup(Z_STRVAL_PP(ppid), Z_STRLEN_PP(ppid))
|
1999-12-22 08:38:04 +08:00
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static void php_session_start(PSLS_D)
|
1999-06-06 06:15:49 +08:00
|
|
|
{
|
|
|
|
pval **ppid;
|
1999-07-16 03:37:35 +08:00
|
|
|
pval **data;
|
1999-07-23 01:55:13 +08:00
|
|
|
char *p;
|
1999-06-06 06:15:49 +08:00
|
|
|
int send_cookie = 1;
|
1999-07-16 03:37:35 +08:00
|
|
|
int define_sid = 1;
|
|
|
|
int module_number = PS(module_number);
|
1999-06-08 00:43:24 +08:00
|
|
|
int nrand;
|
1999-07-23 01:55:13 +08:00
|
|
|
int lensess;
|
1999-06-07 02:22:17 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (PS(nr_open_sessions) != 0)
|
|
|
|
return;
|
1999-07-08 05:50:33 +08:00
|
|
|
|
1999-07-23 01:55:13 +08:00
|
|
|
lensess = strlen(PS(session_name));
|
|
|
|
|
1999-12-22 08:38:04 +08:00
|
|
|
|
|
|
|
/*
|
2000-09-06 03:06:29 +08:00
|
|
|
* Cookies are preferred, because initially
|
1999-12-22 08:38:04 +08:00
|
|
|
* cookie and get variables will be available.
|
|
|
|
*/
|
1999-07-16 03:37:35 +08:00
|
|
|
|
2000-09-06 03:06:29 +08:00
|
|
|
if (!PS(id)) {
|
1999-12-22 08:11:04 +08:00
|
|
|
if (zend_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS",
|
|
|
|
sizeof("HTTP_COOKIE_VARS"), (void **) &data) == SUCCESS &&
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_PP(data) == IS_ARRAY &&
|
|
|
|
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
|
1999-12-22 08:11:04 +08:00
|
|
|
lensess + 1, (void **) &ppid) == SUCCESS) {
|
1999-12-22 08:38:04 +08:00
|
|
|
PPID2SID;
|
1999-12-22 08:11:04 +08:00
|
|
|
define_sid = 0;
|
1999-12-22 08:38:04 +08:00
|
|
|
send_cookie = 0;
|
1999-12-22 08:11:04 +08:00
|
|
|
}
|
|
|
|
|
1999-12-22 08:38:04 +08:00
|
|
|
if (!PS(id) &&
|
1999-12-22 08:11:04 +08:00
|
|
|
zend_hash_find(&EG(symbol_table), "HTTP_GET_VARS",
|
|
|
|
sizeof("HTTP_GET_VARS"), (void **) &data) == SUCCESS &&
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_PP(data) == IS_ARRAY &&
|
|
|
|
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
|
1999-12-22 08:11:04 +08:00
|
|
|
lensess + 1, (void **) &ppid) == SUCCESS) {
|
1999-12-22 08:38:04 +08:00
|
|
|
PPID2SID;
|
1999-12-22 08:11:04 +08:00
|
|
|
}
|
|
|
|
|
1999-12-22 08:38:04 +08:00
|
|
|
if (!PS(id) &&
|
1999-12-22 08:11:04 +08:00
|
|
|
zend_hash_find(&EG(symbol_table), "HTTP_POST_VARS",
|
|
|
|
sizeof("HTTP_POST_VARS"), (void **) &data) == SUCCESS &&
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_PP(data) == IS_ARRAY &&
|
|
|
|
zend_hash_find(Z_ARRVAL_PP(data), PS(session_name),
|
1999-12-22 08:11:04 +08:00
|
|
|
lensess + 1, (void **) &ppid) == SUCCESS) {
|
1999-12-22 08:38:04 +08:00
|
|
|
PPID2SID;
|
1999-12-22 08:11:04 +08:00
|
|
|
}
|
1999-07-16 03:37:35 +08:00
|
|
|
}
|
1999-07-23 01:55:13 +08:00
|
|
|
|
1999-08-22 04:48:40 +08:00
|
|
|
/* check the REQUEST_URI symbol for a string of the form
|
|
|
|
'<session-name>=<session-id>' to allow URLs of the form
|
|
|
|
http://yoursite/<session-name>=<session-id>/script.php */
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (!PS(id) &&
|
1999-12-12 22:22:55 +08:00
|
|
|
zend_hash_find(&EG(symbol_table), "REQUEST_URI",
|
1999-07-23 01:55:13 +08:00
|
|
|
sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_PP(data) == IS_STRING &&
|
|
|
|
(p = strstr(Z_STRVAL_PP(data), PS(session_name))) &&
|
1999-07-23 01:55:13 +08:00
|
|
|
p[lensess] == '=') {
|
|
|
|
char *q;
|
|
|
|
|
|
|
|
p += lensess + 1;
|
2000-02-11 20:59:08 +08:00
|
|
|
if ((q = strpbrk(p, "/?\\")))
|
1999-07-23 01:55:13 +08:00
|
|
|
PS(id) = estrndup(p, q - p);
|
|
|
|
}
|
1999-08-22 04:48:40 +08:00
|
|
|
|
|
|
|
/* check whether the current request was referred to by
|
|
|
|
an external site which invalidates the previously found id */
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(id) &&
|
1999-08-22 04:48:40 +08:00
|
|
|
PS(extern_referer_chk)[0] != '\0' &&
|
|
|
|
zend_hash_find(&EG(symbol_table), "HTTP_REFERER",
|
|
|
|
sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_TYPE_PP(data) == IS_STRING &&
|
|
|
|
Z_STRLEN_PP(data) != 0 &&
|
|
|
|
strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL) {
|
1999-08-22 04:48:40 +08:00
|
|
|
efree(PS(id));
|
|
|
|
PS(id) = NULL;
|
|
|
|
send_cookie = 1;
|
|
|
|
define_sid = 1;
|
|
|
|
}
|
1999-06-06 06:15:49 +08:00
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (!PS(id))
|
1999-09-12 17:57:51 +08:00
|
|
|
PS(id) = _php_create_id(NULL PSLS_CC);
|
1999-10-22 16:10:08 +08:00
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (!PS(use_cookies) && send_cookie) {
|
1999-10-22 16:10:08 +08:00
|
|
|
define_sid = 1;
|
|
|
|
send_cookie = 0;
|
|
|
|
}
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (send_cookie)
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_send_cookie(PSLS_C);
|
1999-07-16 03:37:35 +08:00
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (define_sid) {
|
2001-03-14 00:58:36 +08:00
|
|
|
smart_str var = {0};
|
1999-07-16 03:37:35 +08:00
|
|
|
|
2001-03-14 00:58:36 +08:00
|
|
|
smart_str_appends(&var, PS(session_name));
|
|
|
|
smart_str_appendc(&var, '=');
|
|
|
|
smart_str_appends(&var, PS(id));
|
|
|
|
smart_str_0(&var);
|
2001-03-14 01:11:43 +08:00
|
|
|
REGISTER_STRING_CONSTANT("SID", var.c, 0);
|
2000-02-11 21:41:30 +08:00
|
|
|
} else
|
1999-07-16 05:14:46 +08:00
|
|
|
REGISTER_STRING_CONSTANT("SID", empty_string, 0);
|
1999-09-12 07:47:16 +08:00
|
|
|
PS(define_sid) = define_sid;
|
1999-07-16 03:37:35 +08:00
|
|
|
|
1999-06-06 06:15:49 +08:00
|
|
|
PS(nr_open_sessions)++;
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_cache_limiter(PSLS_C);
|
|
|
|
php_session_initialize(PSLS_C);
|
1999-06-08 00:43:24 +08:00
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(mod_data) && PS(gc_probability) > 0) {
|
2000-03-30 04:37:29 +08:00
|
|
|
int nrdels = -1;
|
|
|
|
|
1999-06-08 00:43:24 +08:00
|
|
|
srand(time(NULL));
|
1999-06-11 17:23:00 +08:00
|
|
|
nrand = (int) (100.0*rand()/RAND_MAX);
|
2000-03-30 04:37:29 +08:00
|
|
|
if (nrand < PS(gc_probability)) {
|
|
|
|
PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels);
|
2000-09-20 09:38:39 +08:00
|
|
|
#if 0
|
2000-03-30 04:37:29 +08:00
|
|
|
if (nrdels != -1)
|
2000-06-28 07:09:49 +08:00
|
|
|
php_error(E_NOTICE, "purged %d expired session objects\n", nrdels);
|
2000-09-20 09:38:39 +08:00
|
|
|
#endif
|
2000-03-30 04:37:29 +08:00
|
|
|
}
|
1999-06-08 00:43:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
static zend_bool php_session_destroy(PSLS_D)
|
1999-06-08 00:43:24 +08:00
|
|
|
{
|
2000-07-05 09:26:22 +08:00
|
|
|
zend_bool retval = SUCCESS;
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (PS(nr_open_sessions) == 0) {
|
1999-09-12 06:31:04 +08:00
|
|
|
php_error(E_WARNING, "Trying to destroy uninitialized session");
|
2000-07-05 09:26:22 +08:00
|
|
|
return FAILURE;
|
1999-09-12 06:31:04 +08:00
|
|
|
}
|
1999-06-08 00:43:24 +08:00
|
|
|
|
2000-01-15 20:17:18 +08:00
|
|
|
if (PS(mod)->destroy(&PS(mod_data), PS(id)) == FAILURE) {
|
2000-07-05 09:26:22 +08:00
|
|
|
retval = FAILURE;
|
2000-07-28 00:43:38 +08:00
|
|
|
php_error(E_WARNING, "Session object destruction failed");
|
2000-01-15 20:17:18 +08:00
|
|
|
}
|
2000-07-05 09:26:22 +08:00
|
|
|
|
1999-06-11 17:23:00 +08:00
|
|
|
php_rshutdown_session_globals(PSLS_C);
|
1999-09-12 06:31:04 +08:00
|
|
|
php_rinit_session_globals(PSLS_C);
|
2000-07-05 09:26:22 +08:00
|
|
|
|
|
|
|
return retval;
|
1999-06-06 06:15:49 +08:00
|
|
|
}
|
|
|
|
|
2000-02-05 07:34:24 +08:00
|
|
|
|
2000-10-29 01:13:28 +08:00
|
|
|
/* {{{ proto void session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure]]])
|
2000-02-05 07:34:24 +08:00
|
|
|
Set session cookie parameters */
|
|
|
|
PHP_FUNCTION(session_set_cookie_params)
|
|
|
|
{
|
2000-10-29 01:13:28 +08:00
|
|
|
zval **lifetime, **path, **domain, **secure;
|
2000-02-05 07:34:24 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
if (!PS(use_cookies))
|
|
|
|
return;
|
|
|
|
|
2000-10-29 01:13:28 +08:00
|
|
|
if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 4 ||
|
|
|
|
zend_get_parameters_ex(ZEND_NUM_ARGS(), &lifetime, &path, &domain, &secure) == FAILURE)
|
2000-02-05 07:34:24 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
|
|
|
convert_to_long_ex(lifetime);
|
2000-09-06 22:13:31 +08:00
|
|
|
PS(cookie_lifetime) = Z_LVAL_PP(lifetime);
|
2000-02-05 07:34:24 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() > 1) {
|
|
|
|
convert_to_string_ex(path);
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.cookie_path", sizeof("session.cookie_path"), Z_STRVAL_PP(path), Z_STRLEN_PP(path), PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
2000-02-05 07:34:24 +08:00
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() > 2) {
|
|
|
|
convert_to_string_ex(domain);
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.cookie_domain", sizeof("session.cookie_domain"), Z_STRVAL_PP(domain), Z_STRLEN_PP(domain), PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
2000-10-29 01:13:28 +08:00
|
|
|
if (ZEND_NUM_ARGS() > 3) {
|
|
|
|
convert_to_long_ex(secure);
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.cookie_secure", sizeof("session.cookie_secure"), Z_BVAL_PP(secure)?"1":"0", 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
2000-10-29 01:13:28 +08:00
|
|
|
}
|
2000-02-05 07:34:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-06-24 01:37:49 +08:00
|
|
|
/* {{{ proto array session_get_cookie_params(void)
|
2000-03-31 02:50:09 +08:00
|
|
|
Return the session cookie parameters */
|
2000-03-31 04:02:21 +08:00
|
|
|
PHP_FUNCTION(session_get_cookie_params)
|
|
|
|
{
|
2000-03-31 02:50:09 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
2000-03-31 02:50:09 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
|
|
|
php_error(E_ERROR, "Cannot initialize return value from session_get_cookie_parameters");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-03-31 06:38:50 +08:00
|
|
|
add_assoc_long(return_value, "lifetime", PS(cookie_lifetime));
|
2000-03-31 06:21:23 +08:00
|
|
|
add_assoc_string(return_value, "path", PS(cookie_path), 1);
|
|
|
|
add_assoc_string(return_value, "domain", PS(cookie_domain), 1);
|
2000-10-29 01:13:28 +08:00
|
|
|
add_assoc_bool(return_value, "secure", PS(cookie_secure));
|
2000-03-31 02:50:09 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
2000-02-05 07:34:24 +08:00
|
|
|
|
1999-06-06 22:19:55 +08:00
|
|
|
/* {{{ proto string session_name([string newname])
|
2000-06-24 01:37:49 +08:00
|
|
|
Return the current session name. If newname is given, the session name is replaced with newname */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_name)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **p_name;
|
2000-06-06 03:47:54 +08:00
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-06-06 03:52:58 +08:00
|
|
|
char *old;
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
old = estrdup(PS(session_name));
|
|
|
|
|
2000-02-23 06:52:14 +08:00
|
|
|
if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (ac == 1) {
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(p_name);
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.name", sizeof("session.name"), Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name), PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL_STRING(old, 0);
|
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-06-06 22:19:55 +08:00
|
|
|
/* {{{ proto string session_module_name([string newname])
|
2000-06-24 01:37:49 +08:00
|
|
|
Return the current module name used for accessing session data. If newname is given, the module name is replaced with newname */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_module_name)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **p_name;
|
2000-06-06 03:47:54 +08:00
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-06-06 03:52:58 +08:00
|
|
|
char *old;
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
old = estrdup(PS(mod)->name);
|
|
|
|
|
2000-02-23 06:52:14 +08:00
|
|
|
if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (ac == 1) {
|
1999-06-06 03:52:58 +08:00
|
|
|
ps_module *tempmod;
|
|
|
|
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(p_name);
|
2000-09-06 22:13:31 +08:00
|
|
|
tempmod = _php_find_ps_module(Z_STRVAL_PP(p_name) PSLS_CC);
|
2000-02-11 20:59:08 +08:00
|
|
|
if (tempmod) {
|
|
|
|
if (PS(mod_data))
|
1999-06-06 03:52:58 +08:00
|
|
|
PS(mod)->close(&PS(mod_data));
|
2000-07-03 00:27:39 +08:00
|
|
|
PS(mod) = tempmod;
|
|
|
|
PS(mod_data) = NULL;
|
1999-06-06 03:52:58 +08:00
|
|
|
} else {
|
|
|
|
efree(old);
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_ERROR, "Cannot find named PHP session module (%s)",
|
2000-09-06 22:13:31 +08:00
|
|
|
Z_STRVAL_PP(p_name));
|
1999-06-06 03:52:58 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL_STRING(old, 0);
|
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
/* {{{ proto void session_set_save_handler(string open, string close, string read, string write, string destroy, string gc)
|
2000-02-24 23:11:09 +08:00
|
|
|
Sets user-level functions */
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_FUNCTION(session_set_save_handler)
|
|
|
|
{
|
|
|
|
zval **args[6];
|
|
|
|
int i;
|
|
|
|
ps_user *mdata;
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_array_ex(6, args) == FAILURE)
|
1999-09-17 13:40:59 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (PS(nr_open_sessions) > 0)
|
1999-09-17 13:40:59 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2000-05-26 21:02:11 +08:00
|
|
|
mdata = emalloc(sizeof(*mdata));
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
for (i = 0; i < 6; i++) {
|
2000-10-12 03:47:15 +08:00
|
|
|
ZVAL_ADDREF(*args[i]);
|
|
|
|
mdata->names[i] = *args[i];
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
2000-10-12 03:47:15 +08:00
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
PS(mod_data) = (void *) mdata;
|
|
|
|
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-06-06 22:19:55 +08:00
|
|
|
/* {{{ proto string session_save_path([string newname])
|
2000-06-24 01:37:49 +08:00
|
|
|
Return the current save path passed to module_name. If newname is given, the save path is replaced with newname */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_save_path)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **p_name;
|
2000-06-06 03:47:54 +08:00
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-06-06 03:52:58 +08:00
|
|
|
char *old;
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
old = estrdup(PS(save_path));
|
|
|
|
|
2000-02-23 06:52:14 +08:00
|
|
|
if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (ac == 1) {
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(p_name);
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.save_path", sizeof("session.save_path"), Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name), PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL_STRING(old, 0);
|
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-06-06 22:19:55 +08:00
|
|
|
/* {{{ proto string session_id([string newid])
|
2000-06-24 01:37:49 +08:00
|
|
|
Return the current session id. If newid is given, the session id is replaced with newid */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_id)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **p_name;
|
2000-06-06 03:47:54 +08:00
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-06-06 03:52:58 +08:00
|
|
|
char *old = empty_string;
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(id))
|
1999-06-06 03:52:58 +08:00
|
|
|
old = estrdup(PS(id));
|
|
|
|
|
2000-02-23 06:52:14 +08:00
|
|
|
if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (ac == 1) {
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(p_name);
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(id)) efree(PS(id));
|
2000-09-06 22:13:31 +08:00
|
|
|
PS(id) = estrndup(Z_STRVAL_PP(p_name), Z_STRLEN_PP(p_name));
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL_STRING(old, 0);
|
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-09-01 23:56:26 +08:00
|
|
|
/* {{{ proto string session_cache_limiter([string new_cache_limiter])
|
|
|
|
Return the current cache limiter. If new_cache_limited is given, the current cache_limiter is replaced with new_cache_limiter */
|
|
|
|
PHP_FUNCTION(session_cache_limiter)
|
|
|
|
{
|
|
|
|
pval **p_cache_limiter;
|
|
|
|
int ac = ZEND_NUM_ARGS();
|
|
|
|
char *old;
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
old = estrdup(PS(cache_limiter));
|
|
|
|
|
|
|
|
if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &p_cache_limiter) == FAILURE)
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
|
|
|
if (ac == 1) {
|
|
|
|
convert_to_string_ex(p_cache_limiter);
|
2000-10-29 19:38:26 +08:00
|
|
|
zend_alter_ini_entry("session.cache_limiter", sizeof("session.cache_limiter"), Z_STRVAL_PP(p_cache_limiter), Z_STRLEN_PP(p_cache_limiter), PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
|
2000-09-01 23:56:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL_STRING(old, 0);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-11-28 05:18:41 +08:00
|
|
|
|
1999-12-05 01:02:04 +08:00
|
|
|
/* {{{ static void php_register_var(zval** entry PSLS_DC PLS_DC) */
|
|
|
|
static void php_register_var(zval** entry PSLS_DC PLS_DC)
|
1999-11-28 05:18:41 +08:00
|
|
|
{
|
2000-02-11 21:41:30 +08:00
|
|
|
zval **value;
|
1999-11-28 05:18:41 +08:00
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
if (Z_TYPE_PP(entry) == IS_ARRAY) {
|
|
|
|
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(entry));
|
1999-11-28 05:18:41 +08:00
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
while (zend_hash_get_current_data(Z_ARRVAL_PP(entry), (void**)&value) == SUCCESS) {
|
1999-12-05 01:05:45 +08:00
|
|
|
php_register_var(value PSLS_CC PLS_CC);
|
2000-09-06 22:13:31 +08:00
|
|
|
zend_hash_move_forward(Z_ARRVAL_PP(entry));
|
1999-11-28 05:18:41 +08:00
|
|
|
}
|
2000-01-18 06:41:59 +08:00
|
|
|
} else {
|
1999-11-28 05:18:41 +08:00
|
|
|
convert_to_string_ex(entry);
|
2000-01-18 06:41:59 +08:00
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
if (strcmp(Z_STRVAL_PP(entry), "HTTP_SESSION_VARS") != 0)
|
|
|
|
PS_ADD_VARL(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
|
1999-11-28 05:18:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2000-06-24 01:37:49 +08:00
|
|
|
/* {{{ proto bool session_register(mixed var_names [, mixed ...])
|
2000-02-24 23:11:09 +08:00
|
|
|
Adds varname(s) to the list of variables which are freezed at the session end */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_register)
|
|
|
|
{
|
2000-02-11 21:41:30 +08:00
|
|
|
zval ***args;
|
2000-06-06 03:47:54 +08:00
|
|
|
int argc = ZEND_NUM_ARGS();
|
1999-11-28 05:18:41 +08:00
|
|
|
int i;
|
1999-06-06 03:52:58 +08:00
|
|
|
PSLS_FETCH();
|
1999-12-05 01:02:04 +08:00
|
|
|
PLS_FETCH();
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (argc <= 0)
|
|
|
|
RETURN_FALSE
|
|
|
|
else
|
1999-11-28 05:18:41 +08:00
|
|
|
args = (zval ***)emalloc(argc * sizeof(zval **));
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
|
1999-11-28 05:18:41 +08:00
|
|
|
efree(args);
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (PS(nr_open_sessions) == 0)
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_start(PSLS_C);
|
1999-11-28 05:18:41 +08:00
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
for (i = 0; i < argc; i++) {
|
2000-09-06 22:13:31 +08:00
|
|
|
if (Z_TYPE_PP(args[i]) == IS_ARRAY)
|
1999-11-28 05:18:41 +08:00
|
|
|
SEPARATE_ZVAL(args[i]);
|
1999-12-05 01:05:45 +08:00
|
|
|
php_register_var(args[i] PSLS_CC PLS_CC);
|
1999-11-28 05:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
efree(args);
|
1999-10-25 00:17:45 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-10-25 00:17:45 +08:00
|
|
|
/* {{{ proto bool session_unregister(string varname)
|
2000-02-24 23:11:09 +08:00
|
|
|
Removes varname from the list of variables which are freezed at the session end */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_unregister)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **p_name;
|
2000-06-06 03:47:54 +08:00
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-06-06 03:52:58 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (ac != 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(p_name);
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
PS_DEL_VAR(Z_STRVAL_PP(p_name));
|
1999-10-25 00:17:45 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
1999-06-28 23:46:56 +08:00
|
|
|
|
|
|
|
/* {{{ proto bool session_is_registered(string varname)
|
2000-02-24 23:11:09 +08:00
|
|
|
Checks if a variable is registered in session */
|
1999-06-28 23:46:56 +08:00
|
|
|
PHP_FUNCTION(session_is_registered)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **p_name;
|
1999-06-28 23:46:56 +08:00
|
|
|
pval *p_var;
|
2000-06-06 03:47:54 +08:00
|
|
|
int ac = ZEND_NUM_ARGS();
|
1999-06-28 23:46:56 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-02-11 21:41:30 +08:00
|
|
|
if (ac != 1 || zend_get_parameters_ex(ac, &p_name) == FAILURE)
|
1999-06-28 23:46:56 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(p_name);
|
1999-06-28 23:46:56 +08:00
|
|
|
|
2000-09-06 22:13:31 +08:00
|
|
|
if (zend_hash_find(&PS(vars), Z_STRVAL_PP(p_name),
|
|
|
|
Z_STRLEN_PP(p_name)+1, (void **)&p_var) == SUCCESS)
|
2000-02-11 21:41:30 +08:00
|
|
|
RETURN_TRUE
|
|
|
|
else
|
1999-06-28 23:46:56 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2000-02-24 23:11:09 +08:00
|
|
|
/* {{{ proto string session_encode(void)
|
|
|
|
Serializes the current setup and returns the serialized representation */
|
1999-06-06 23:18:51 +08:00
|
|
|
PHP_FUNCTION(session_encode)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *enc;
|
1999-06-07 03:53:59 +08:00
|
|
|
PSLS_FETCH();
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
enc = php_session_encode(&len PSLS_CC);
|
1999-06-06 03:52:58 +08:00
|
|
|
RETVAL_STRINGL(enc, len, 0);
|
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-05-24 07:13:02 +08:00
|
|
|
/* {{{ proto bool session_decode(string data)
|
2000-02-24 23:11:09 +08:00
|
|
|
Deserializes data and reinitializes the variables */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_decode)
|
|
|
|
{
|
1999-09-17 17:26:03 +08:00
|
|
|
pval **str;
|
1999-06-07 03:53:59 +08:00
|
|
|
PSLS_FETCH();
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE)
|
1999-06-06 03:52:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
|
1999-09-17 17:26:03 +08:00
|
|
|
convert_to_string_ex(str);
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_decode(Z_STRVAL_PP(str), Z_STRLEN_PP(str) PSLS_CC);
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-05-24 07:13:02 +08:00
|
|
|
/* {{{ proto bool session_start(void)
|
1999-06-06 22:19:55 +08:00
|
|
|
Begin session - reinitializes freezed variables, registers browsers etc */
|
1999-06-06 03:52:58 +08:00
|
|
|
PHP_FUNCTION(session_start)
|
|
|
|
{
|
1999-06-07 03:25:39 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_start(PSLS_C);
|
1999-08-23 23:37:11 +08:00
|
|
|
|
|
|
|
RETURN_TRUE;
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
1999-06-06 22:19:55 +08:00
|
|
|
/* }}} */
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-07-05 09:26:22 +08:00
|
|
|
/* {{{ proto bool session_destroy(void)
|
1999-06-08 00:43:24 +08:00
|
|
|
Destroy the current session and all data associated with it */
|
|
|
|
PHP_FUNCTION(session_destroy)
|
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
2000-07-05 09:26:22 +08:00
|
|
|
|
2000-09-06 22:16:12 +08:00
|
|
|
if (php_session_destroy(PSLS_C) == SUCCESS) {
|
2000-07-05 09:26:22 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-06-08 00:43:24 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-09-12 07:47:16 +08:00
|
|
|
#ifdef TRANS_SID
|
2000-10-27 02:10:43 +08:00
|
|
|
void session_adapt_uris(const char *src, size_t srclen, char **new, size_t *newlen)
|
1999-09-12 07:47:16 +08:00
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-10-27 02:10:43 +08:00
|
|
|
if (PS(define_sid) && PS(nr_open_sessions) > 0)
|
|
|
|
*new = url_adapt_ext_ex(src, srclen, PS(session_name), PS(id), newlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void session_adapt_url(const char *url, size_t urllen, char **new, size_t *newlen)
|
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
if (PS(define_sid) && PS(nr_open_sessions) > 0)
|
|
|
|
*new = url_adapt_single_url(url, urllen, PS(session_name), PS(id), newlen);
|
1999-09-12 07:47:16 +08:00
|
|
|
}
|
|
|
|
#endif
|
1999-09-12 06:31:04 +08:00
|
|
|
|
2000-05-24 07:13:02 +08:00
|
|
|
/* {{{ proto void session_unset(void)
|
1999-09-12 06:31:04 +08:00
|
|
|
Unset all registered variables */
|
|
|
|
PHP_FUNCTION(session_unset)
|
|
|
|
{
|
|
|
|
zval **tmp;
|
|
|
|
char *variable;
|
1999-11-28 05:18:41 +08:00
|
|
|
ulong num_key;
|
1999-09-12 06:31:04 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
2000-12-23 06:53:14 +08:00
|
|
|
if (PS(nr_open_sessions) == 0)
|
|
|
|
RETURN_FALSE;
|
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
for (zend_hash_internal_pointer_reset(&PS(vars));
|
2000-12-22 20:57:09 +08:00
|
|
|
zend_hash_get_current_key(&PS(vars), &variable, &num_key, 0) == HASH_KEY_IS_STRING;
|
1999-09-12 06:31:04 +08:00
|
|
|
zend_hash_move_forward(&PS(vars))) {
|
2000-02-11 20:59:08 +08:00
|
|
|
if (zend_hash_find(&EG(symbol_table), variable, strlen(variable) + 1, (void **) &tmp)
|
2000-02-11 21:41:30 +08:00
|
|
|
== SUCCESS)
|
1999-09-12 08:07:10 +08:00
|
|
|
zend_hash_del(&EG(symbol_table), variable, strlen(variable) + 1);
|
1999-09-12 06:31:04 +08:00
|
|
|
}
|
2000-10-27 01:37:47 +08:00
|
|
|
|
|
|
|
/* Clean $HTTP_SESSION_VARS. */
|
|
|
|
zend_hash_clean(Z_ARRVAL_P(PS(http_session_vars)));
|
1999-09-12 06:31:04 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-06-11 17:23:00 +08:00
|
|
|
static void php_rinit_session_globals(PSLS_D)
|
2000-05-26 21:02:11 +08:00
|
|
|
{
|
1999-06-07 02:36:42 +08:00
|
|
|
zend_hash_init(&PS(vars), 0, NULL, NULL, 0);
|
1999-09-12 07:47:16 +08:00
|
|
|
PS(define_sid) = 0;
|
1999-06-07 02:39:48 +08:00
|
|
|
PS(id) = NULL;
|
|
|
|
PS(nr_open_sessions) = 0;
|
|
|
|
PS(mod_data) = NULL;
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
1999-06-11 17:23:00 +08:00
|
|
|
static void php_rshutdown_session_globals(PSLS_D)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(mod_data))
|
1999-06-07 02:39:48 +08:00
|
|
|
PS(mod)->close(&PS(mod_data));
|
2000-02-11 21:41:30 +08:00
|
|
|
if (PS(id))
|
|
|
|
efree(PS(id));
|
1999-06-07 02:39:48 +08:00
|
|
|
zend_hash_destroy(&PS(vars));
|
1999-06-06 03:52:58 +08:00
|
|
|
}
|
|
|
|
|
1999-11-18 06:59:27 +08:00
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_RINIT_FUNCTION(session)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
1999-06-07 02:36:42 +08:00
|
|
|
PSLS_FETCH();
|
|
|
|
|
1999-06-11 17:23:00 +08:00
|
|
|
php_rinit_session_globals(PSLS_C);
|
1999-06-07 02:22:17 +08:00
|
|
|
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(mod) == NULL) {
|
2001-05-24 07:18:51 +08:00
|
|
|
char *value;
|
|
|
|
|
|
|
|
value = zend_ini_string("session.save_handler", sizeof("session.save_handler"), 0);
|
|
|
|
if (value) {
|
|
|
|
PS(mod) = _php_find_ps_module(value PSLS_CC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PS(mod)) {
|
|
|
|
/* current status is unusable */
|
|
|
|
PS(nr_open_sessions) = -1;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-08-28 05:03:22 +08:00
|
|
|
}
|
|
|
|
|
2000-05-26 21:02:11 +08:00
|
|
|
if (PS(auto_start)) {
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_start(PSLS_C);
|
2000-05-26 21:02:11 +08:00
|
|
|
}
|
1999-06-06 03:52:58 +08:00
|
|
|
|
2000-01-17 05:03:49 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2000-01-15 21:09:32 +08:00
|
|
|
|
2000-10-12 03:47:15 +08:00
|
|
|
static void php_session_flush(PSLS_D)
|
2000-01-17 05:03:49 +08:00
|
|
|
{
|
2000-02-11 20:59:08 +08:00
|
|
|
if (PS(nr_open_sessions) > 0) {
|
2000-09-06 22:16:12 +08:00
|
|
|
php_session_save_current_state(PSLS_C);
|
2000-01-17 05:03:49 +08:00
|
|
|
PS(nr_open_sessions)--;
|
|
|
|
}
|
2000-10-12 03:47:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PHP_FUNCTION(session_write_close)
|
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
|
|
|
php_session_flush(PSLS_C);
|
|
|
|
}
|
|
|
|
|
|
|
|
PHP_RSHUTDOWN_FUNCTION(session)
|
|
|
|
{
|
|
|
|
PSLS_FETCH();
|
|
|
|
|
|
|
|
php_session_flush(PSLS_C);
|
2000-01-17 05:03:49 +08:00
|
|
|
php_rshutdown_session_globals(PSLS_C);
|
1999-06-06 03:52:58 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2000-01-17 05:03:49 +08:00
|
|
|
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MINIT_FUNCTION(session)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
1999-06-07 02:56:11 +08:00
|
|
|
#ifdef ZTS
|
1999-07-17 00:09:01 +08:00
|
|
|
php_ps_globals *ps_globals;
|
|
|
|
|
1999-06-07 02:56:11 +08:00
|
|
|
ps_globals_id = ts_allocate_id(sizeof(php_ps_globals), NULL, NULL);
|
1999-07-17 00:09:01 +08:00
|
|
|
ps_globals = ts_resource(ps_globals_id);
|
1999-06-07 02:56:11 +08:00
|
|
|
#endif
|
1999-07-17 00:09:01 +08:00
|
|
|
|
1999-07-16 03:37:35 +08:00
|
|
|
PS(module_number) = module_number;
|
1999-06-06 03:52:58 +08:00
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MSHUTDOWN_FUNCTION(session)
|
1999-06-06 03:52:58 +08:00
|
|
|
{
|
|
|
|
UNREGISTER_INI_ENTRIES();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-06-07 03:53:59 +08:00
|
|
|
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
PHP_MINFO_FUNCTION(session)
|
1999-06-07 03:53:59 +08:00
|
|
|
{
|
2000-04-07 05:07:44 +08:00
|
|
|
|
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_row(2, "Session Support", "enabled" );
|
|
|
|
php_info_print_table_end();
|
|
|
|
|
1999-06-07 03:53:59 +08:00
|
|
|
DISPLAY_INI_ENTRIES();
|
|
|
|
}
|