Back to index

php5  5.3.10
Classes | Defines | Typedefs | Enumerations | Functions | Variables
php_session.h File Reference
#include "ext/standard/php_var.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ps_module_struct
struct  _php_ps_globals
struct  ps_serializer_struct
union  _php_ps_globals.mod_user_names
struct  _php_ps_globals.mod_user_names.name

Defines

#define PHP_SESSION_API   20020330
#define PS_OPEN_ARGS   void **mod_data, const char *save_path, const char *session_name TSRMLS_DC
#define PS_CLOSE_ARGS   void **mod_data TSRMLS_DC
#define PS_READ_ARGS   void **mod_data, const char *key, char **val, int *vallen TSRMLS_DC
#define PS_WRITE_ARGS   void **mod_data, const char *key, const char *val, const int vallen TSRMLS_DC
#define PS_DESTROY_ARGS   void **mod_data, const char *key TSRMLS_DC
#define PS_GC_ARGS   void **mod_data, int maxlifetime, int *nrdels TSRMLS_DC
#define PS_CREATE_SID_ARGS   void **mod_data, int *newlen TSRMLS_DC
#define PS_GET_MOD_DATA()   *mod_data
#define PS_SET_MOD_DATA(a)   *mod_data = (a)
#define PS_OPEN_FUNC(x)   int ps_open_##x(PS_OPEN_ARGS)
#define PS_CLOSE_FUNC(x)   int ps_close_##x(PS_CLOSE_ARGS)
#define PS_READ_FUNC(x)   int ps_read_##x(PS_READ_ARGS)
#define PS_WRITE_FUNC(x)   int ps_write_##x(PS_WRITE_ARGS)
#define PS_DESTROY_FUNC(x)   int ps_delete_##x(PS_DESTROY_ARGS)
#define PS_GC_FUNC(x)   int ps_gc_##x(PS_GC_ARGS)
#define PS_CREATE_SID_FUNC(x)   char *ps_create_sid_##x(PS_CREATE_SID_ARGS)
#define PS_FUNCS(x)
#define PS_MOD(x)
#define PS_FUNCS_SID(x)
#define PS_MOD_SID(x)
#define phpext_session_ptr   &session_module_entry
#define PS(v)   (ps_globals.v)
#define PS_SERIALIZER_ENCODE_ARGS   char **newstr, int *newlen TSRMLS_DC
#define PS_SERIALIZER_DECODE_ARGS   const char *val, int vallen TSRMLS_DC
#define PS_SERIALIZER_ENCODE_NAME(x)   ps_srlzr_encode_##x
#define PS_SERIALIZER_DECODE_NAME(x)   ps_srlzr_decode_##x
#define PS_SERIALIZER_ENCODE_FUNC(x)   int PS_SERIALIZER_ENCODE_NAME(x)(PS_SERIALIZER_ENCODE_ARGS)
#define PS_SERIALIZER_DECODE_FUNC(x)   int PS_SERIALIZER_DECODE_NAME(x)(PS_SERIALIZER_DECODE_ARGS)
#define PS_SERIALIZER_FUNCS(x)
#define PS_SERIALIZER_ENTRY(x)   { #x, PS_SERIALIZER_ENCODE_NAME(x), PS_SERIALIZER_DECODE_NAME(x) }
#define PS_ADD_VARL(name, namelen)
#define PS_ADD_VAR(name)   PS_ADD_VARL(name, strlen(name))
#define PS_DEL_VARL(name, namelen)
#define PS_ENCODE_VARS
#define PS_ENCODE_LOOP(code)

Typedefs

typedef struct ps_module_struct ps_module
typedef struct _php_ps_globals php_ps_globals
typedef php_ps_globals zend_ps_globals
typedef struct ps_serializer_struct ps_serializer

Enumerations

enum  php_session_status { php_session_disabled, php_session_none, php_session_active }

Functions

PHPAPI char * php_session_create_id (PS_CREATE_SID_ARGS)
PHPAPI void session_adapt_url (const char *, size_t, char **, size_t *TSRMLS_DC)
PHPAPI void php_add_session_var (char *name, size_t namelen TSRMLS_DC)
PHPAPI void php_set_session_var (char *name, size_t namelen, zval *state_val, php_unserialize_data_t *var_hash TSRMLS_DC)
PHPAPI int php_get_session_var (char *name, size_t namelen, zval ***state_var TSRMLS_DC)
PHPAPI int php_session_register_module (ps_module *)
PHPAPI int php_session_register_serializer (const char *name, int(*encode)(PS_SERIALIZER_ENCODE_ARGS), int(*decode)(PS_SERIALIZER_DECODE_ARGS))
PHPAPI void php_session_set_id (char *id TSRMLS_DC)
PHPAPI void php_session_start (TSRMLS_D)
PHPAPI ps_module_php_find_ps_module (char *name TSRMLS_DC)
PHPAPI const ps_serializer_php_find_ps_serializer (char *name TSRMLS_DC)
PHPAPI ZEND_EXTERN_MODULE_GLOBALS (ps) void php_session_auto_start(void *data)
void php_session_shutdown (void *data)

Variables

zend_module_entry session_module_entry

Class Documentation

struct _php_ps_globals

Definition at line 98 of file php_session.h.

Collaboration diagram for _php_ps_globals:
Class Members
zend_bool apply_trans_sid
zend_bool auto_start
zend_bool bug_compat
zend_bool bug_compat_warn
long cache_expire
char * cache_limiter
char * cookie_domain
zend_bool cookie_httponly
long cookie_lifetime
char * cookie_path
zend_bool cookie_secure
int define_sid
char * entropy_file
long entropy_length
char * extern_referer_chk
long gc_divisor
long gc_maxlifetime
long gc_probability
long hash_bits_per_character
long hash_func
zval * http_session_vars
char * id
zend_bool invalid_session_id
ps_module * mod
void * mod_data
union _php_ps_globals mod_user_names
int module_number
char * save_path
int send_cookie
struct ps_serializer_struct * serializer
char * session_name
php_session_status session_status
zend_bool use_cookies
zend_bool use_only_cookies
zend_bool use_trans_sid
union _php_ps_globals.mod_user_names

Definition at line 119 of file php_session.h.

Class Members
mod_user_names name
zval * names
struct _php_ps_globals.mod_user_names.name

Definition at line 121 of file php_session.h.

Class Members
zval * ps_close
zval * ps_destroy
zval * ps_gc
zval * ps_open
zval * ps_read
zval * ps_write

Define Documentation

#define PHP_SESSION_API   20020330

Definition at line 30 of file php_session.h.

Definition at line 153 of file php_session.h.

#define PS (   v)    (ps_globals.v)

Definition at line 158 of file php_session.h.

#define PS_ADD_VAR (   name)    PS_ADD_VARL(name, strlen(name))

Definition at line 207 of file php_session.h.

#define PS_ADD_VARL (   name,
  namelen 
)
Value:
do {                                                                  \
       php_add_session_var(name, namelen TSRMLS_CC);                                              \
} while (0)

Definition at line 203 of file php_session.h.

#define PS_CLOSE_ARGS   void **mod_data TSRMLS_DC

Definition at line 33 of file php_session.h.

#define PS_CLOSE_FUNC (   x)    int ps_close_##x(PS_CLOSE_ARGS)

Definition at line 58 of file php_session.h.

#define PS_CREATE_SID_ARGS   void **mod_data, int *newlen TSRMLS_DC

Definition at line 38 of file php_session.h.

#define PS_CREATE_SID_FUNC (   x)    char *ps_create_sid_##x(PS_CREATE_SID_ARGS)

Definition at line 63 of file php_session.h.

#define PS_DEL_VARL (   name,
  namelen 
)
Value:
do {                                                                  \
       if (PS(http_session_vars)) {                                                                             \
              zend_hash_del(Z_ARRVAL_P(PS(http_session_vars)), name, namelen+1);    \
       }                                                                                                                             \
} while (0)

Definition at line 209 of file php_session.h.

#define PS_DESTROY_ARGS   void **mod_data, const char *key TSRMLS_DC

Definition at line 36 of file php_session.h.

#define PS_DESTROY_FUNC (   x)    int ps_delete_##x(PS_DESTROY_ARGS)

Definition at line 61 of file php_session.h.

#define PS_ENCODE_LOOP (   code)
Value:
do {                                                           \
		HashTable *_ht = Z_ARRVAL_P(PS(http_session_vars));                 \
              int key_type;                                                                              \
																	\
		for (zend_hash_internal_pointer_reset(_ht);                                \
                            (key_type = zend_hash_get_current_key_ex(_ht, &key, &key_length, &num_key, 0, NULL)) != HASH_KEY_NON_EXISTANT; \
                                   zend_hash_move_forward(_ht)) {                                 \
                     if (key_type == HASH_KEY_IS_LONG) {                                          \
                            php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Skipping numeric key %ld", num_key);    \
                            continue;                                                                           \
                     }                                                                                                 \
                     key_length--;                                                                       \
                     if (php_get_session_var(key, key_length, &struc TSRMLS_CC) == SUCCESS) {     \
                            code;                                                                               \
                     }                                                                                                 \
              }                                                                                                        \
       } while(0)

Definition at line 222 of file php_session.h.

#define PS_ENCODE_VARS
Value:
char *key;                                                                                        \
	uint key_length;                                                                          \
	ulong num_key;                                                                                   \
       zval **struc;

Definition at line 216 of file php_session.h.

#define PS_FUNCS (   x)
Value:
PS_OPEN_FUNC(x); \
       PS_CLOSE_FUNC(x); \
       PS_READ_FUNC(x); \
       PS_WRITE_FUNC(x); \
       PS_DESTROY_FUNC(x); \
       PS_GC_FUNC(x);       \
       PS_CREATE_SID_FUNC(x)

Definition at line 65 of file php_session.h.

#define PS_FUNCS_SID (   x)
Value:
PS_OPEN_FUNC(x); \
       PS_CLOSE_FUNC(x); \
       PS_READ_FUNC(x); \
       PS_WRITE_FUNC(x); \
       PS_DESTROY_FUNC(x); \
       PS_GC_FUNC(x); \
       PS_CREATE_SID_FUNC(x)

Definition at line 79 of file php_session.h.

#define PS_GC_ARGS   void **mod_data, int maxlifetime, int *nrdels TSRMLS_DC

Definition at line 37 of file php_session.h.

#define PS_GC_FUNC (   x)    int ps_gc_##x(PS_GC_ARGS)

Definition at line 62 of file php_session.h.

#define PS_GET_MOD_DATA ( )    *mod_data

Definition at line 54 of file php_session.h.

#define PS_MOD (   x)
Value:
#x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
        ps_delete_##x, ps_gc_##x, php_session_create_id

Definition at line 74 of file php_session.h.

#define PS_MOD_SID (   x)
Value:
#x, ps_open_##x, ps_close_##x, ps_read_##x, ps_write_##x, \
        ps_delete_##x, ps_gc_##x, ps_create_sid_##x

Definition at line 88 of file php_session.h.

#define PS_OPEN_ARGS   void **mod_data, const char *save_path, const char *session_name TSRMLS_DC

Definition at line 32 of file php_session.h.

#define PS_OPEN_FUNC (   x)    int ps_open_##x(PS_OPEN_ARGS)

Definition at line 57 of file php_session.h.

#define PS_READ_ARGS   void **mod_data, const char *key, char **val, int *vallen TSRMLS_DC

Definition at line 34 of file php_session.h.

#define PS_READ_FUNC (   x)    int ps_read_##x(PS_READ_ARGS)

Definition at line 59 of file php_session.h.

#define PS_SERIALIZER_DECODE_ARGS   const char *val, int vallen TSRMLS_DC

Definition at line 162 of file php_session.h.

Definition at line 175 of file php_session.h.

#define PS_SERIALIZER_DECODE_NAME (   x)    ps_srlzr_decode_##x

Definition at line 171 of file php_session.h.

#define PS_SERIALIZER_ENCODE_ARGS   char **newstr, int *newlen TSRMLS_DC

Definition at line 161 of file php_session.h.

Definition at line 173 of file php_session.h.

#define PS_SERIALIZER_ENCODE_NAME (   x)    ps_srlzr_encode_##x

Definition at line 170 of file php_session.h.

Definition at line 182 of file php_session.h.

#define PS_SERIALIZER_FUNCS (   x)
Value:
PS_SERIALIZER_ENCODE_FUNC(x); \
       PS_SERIALIZER_DECODE_FUNC(x)

Definition at line 178 of file php_session.h.

#define PS_SET_MOD_DATA (   a)    *mod_data = (a)

Definition at line 55 of file php_session.h.

#define PS_WRITE_ARGS   void **mod_data, const char *key, const char *val, const int vallen TSRMLS_DC

Definition at line 35 of file php_session.h.

#define PS_WRITE_FUNC (   x)    int ps_write_##x(PS_WRITE_ARGS)

Definition at line 60 of file php_session.h.


Typedef Documentation

typedef struct ps_module_struct ps_module

Definition at line 150 of file php_session.h.


Enumeration Type Documentation

Enumerator:
php_session_disabled 
php_session_none 
php_session_active 

Definition at line 92 of file php_session.h.


Function Documentation

PHPAPI ps_module* _php_find_ps_module ( char *name  TSRMLS_DC)

Definition at line 1295 of file session.c.

{
       ps_module *ret = NULL;
       ps_module **mod;
       int i;

       for (i = 0, mod = ps_modules; i < MAX_MODULES; i++, mod++) {
              if (*mod && !strcasecmp(name, (*mod)->s_name)) {
                     ret = *mod;
                     break;
              }
       }
       return ret;
}

Here is the caller graph for this function:

PHPAPI const ps_serializer* _php_find_ps_serializer ( char *name  TSRMLS_DC)

Definition at line 1311 of file session.c.

{
       const ps_serializer *ret = NULL;
       const ps_serializer *mod;

       for (mod = ps_serializers; mod->name; mod++) {
              if (!strcasecmp(name, mod->name)) {
                     ret = mod;
                     break;
              }
       }
       return ret;
}

Here is the caller graph for this function:

PHPAPI void php_add_session_var ( char *  name,
size_t namelen  TSRMLS_DC 
)

Definition at line 125 of file session.c.

{
       zval **sym_track = NULL;

       IF_SESSION_VARS() {
              zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void *) &sym_track);
       } else {
              return;
       }

       /* Set up a proper reference between $_SESSION["x"] and $x. */

       if (PG(register_globals)) {
              zval **sym_global = NULL;

              if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void *) &sym_global) == SUCCESS) {
                     if ((Z_TYPE_PP(sym_global) == IS_ARRAY && Z_ARRVAL_PP(sym_global) == &EG(symbol_table)) || *sym_global == PS(http_session_vars)) {
                            return;
                     }
              }

              if (sym_global == NULL && sym_track == NULL) {
                     zval *empty_var;

                     ALLOC_INIT_ZVAL(empty_var); /* this sets refcount to 1 */
                     Z_SET_REFCOUNT_P(empty_var, 0); /* our module does not maintain a ref */
                     /* The next call will increase refcount by NR_OF_SYM_TABLES==2 */
                     zend_set_hash_symbol(empty_var, name, namelen, 1, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table));
              } else if (sym_global == NULL) {
                     SEPARATE_ZVAL_IF_NOT_REF(sym_track);
                     zend_set_hash_symbol(*sym_track, name, namelen, 1, 1, &EG(symbol_table));
              } else if (sym_track == NULL) {
                     SEPARATE_ZVAL_IF_NOT_REF(sym_global);
                     zend_set_hash_symbol(*sym_global, name, namelen, 1, 1, Z_ARRVAL_P(PS(http_session_vars)));
              }
       } else {
              if (sym_track == NULL) {
                     zval *empty_var;

                     ALLOC_INIT_ZVAL(empty_var);
                     ZEND_SET_SYMBOL_WITH_LENGTH(Z_ARRVAL_P(PS(http_session_vars)), name, namelen+1, empty_var, 1, 0);
              }
       }
}

Here is the call graph for this function:

PHPAPI int php_get_session_var ( char *  name,
size_t  namelen,
zval ***state_var  TSRMLS_DC 
)

Definition at line 210 of file session.c.

{
       int ret = FAILURE;

       IF_SESSION_VARS() {
              ret = zend_hash_find(Z_ARRVAL_P(PS(http_session_vars)), name, namelen + 1, (void **) state_var);

              /* If register_globals is enabled, and
               * if there is an entry for the slot in $_SESSION, and
               * if that entry is still set to NULL, and
               * if the global var exists, then
               * we prefer the same key in the global sym table. */

              if (PG(register_globals) && ret == SUCCESS && Z_TYPE_PP(*state_var) == IS_NULL) {
                     zval **tmp;

                     if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) {
                            *state_var = tmp;
                     }
              }
       }
       return ret;
}

Here is the call graph for this function:

Definition at line 345 of file session.c.

{
       PHP_MD5_CTX md5_context;
       PHP_SHA1_CTX sha1_context;
#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
       void *hash_context;
#endif
       unsigned char *digest;
       int digest_len;
       int j;
       char *buf, *outid;
       struct timeval tv;
       zval **array;
       zval **token;
       char *remote_addr = NULL;

       gettimeofday(&tv, NULL);

       if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &array) == SUCCESS &&
              Z_TYPE_PP(array) == IS_ARRAY &&
              zend_hash_find(Z_ARRVAL_PP(array), "REMOTE_ADDR", sizeof("REMOTE_ADDR"), (void **) &token) == SUCCESS
       ) {
              remote_addr = Z_STRVAL_PP(token);
       }

       /* maximum 15+19+19+10 bytes */
       spprintf(&buf, 0, "%.15s%ld%ld%0.8F", remote_addr ? remote_addr : "", tv.tv_sec, (long int)tv.tv_usec, php_combined_lcg(TSRMLS_C) * 10);

       switch (PS(hash_func)) {
              case PS_HASH_FUNC_MD5:
                     PHP_MD5Init(&md5_context);
                     PHP_MD5Update(&md5_context, (unsigned char *) buf, strlen(buf));
                     digest_len = 16;
                     break;
              case PS_HASH_FUNC_SHA1:
                     PHP_SHA1Init(&sha1_context);
                     PHP_SHA1Update(&sha1_context, (unsigned char *) buf, strlen(buf));
                     digest_len = 20;
                     break;
#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
              case PS_HASH_FUNC_OTHER:
                     if (!PS(hash_ops)) {
                            php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid session hash function");
                            efree(buf);
                            return NULL;
                     }

                     hash_context = emalloc(PS(hash_ops)->context_size);
                     PS(hash_ops)->hash_init(hash_context);
                     PS(hash_ops)->hash_update(hash_context, (unsigned char *) buf, strlen(buf));
                     digest_len = PS(hash_ops)->digest_size;
                     break;
#endif /* HAVE_HASH_EXT */
              default:
                     php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid session hash function");
                     efree(buf);
                     return NULL;
       }
       efree(buf);

       if (PS(entropy_length) > 0) {
#ifdef PHP_WIN32
              unsigned char rbuf[2048];
              size_t toread = PS(entropy_length);

              if (php_win32_get_random_bytes(rbuf, (size_t) toread) == SUCCESS){

                     switch (PS(hash_func)) {
                            case PS_HASH_FUNC_MD5:
                                   PHP_MD5Update(&md5_context, rbuf, toread);
                                   break;
                            case PS_HASH_FUNC_SHA1:
                                   PHP_SHA1Update(&sha1_context, rbuf, toread);
                                   break;
# if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
                            case PS_HASH_FUNC_OTHER:
                                   PS(hash_ops)->hash_update(hash_context, rbuf, toread);
                                   break;
# endif /* HAVE_HASH_EXT */
                     }
              }
#else
              int fd;

              fd = VCWD_OPEN(PS(entropy_file), O_RDONLY);
              if (fd >= 0) {
                     unsigned char rbuf[2048];
                     int n;
                     int to_read = PS(entropy_length);

                     while (to_read > 0) {
                            n = read(fd, rbuf, MIN(to_read, sizeof(rbuf)));
                            if (n <= 0) break;

                            switch (PS(hash_func)) {
                                   case PS_HASH_FUNC_MD5:
                                          PHP_MD5Update(&md5_context, rbuf, n);
                                          break;
                                   case PS_HASH_FUNC_SHA1:
                                          PHP_SHA1Update(&sha1_context, rbuf, n);
                                          break;
#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
                                   case PS_HASH_FUNC_OTHER:
                                          PS(hash_ops)->hash_update(hash_context, rbuf, n);
                                          break;
#endif /* HAVE_HASH_EXT */
                            }
                            to_read -= n;
                     }
                     close(fd);
              }
#endif
       }

       digest = emalloc(digest_len + 1);
       switch (PS(hash_func)) {
              case PS_HASH_FUNC_MD5:
                     PHP_MD5Final(digest, &md5_context);
                     break;
              case PS_HASH_FUNC_SHA1:
                     PHP_SHA1Final(digest, &sha1_context);
                     break;
#if defined(HAVE_HASH_EXT) && !defined(COMPILE_DL_HASH)
              case PS_HASH_FUNC_OTHER:
                     PS(hash_ops)->hash_final(digest, hash_context);
                     efree(hash_context);
                     break;
#endif /* HAVE_HASH_EXT */
       }

       if (PS(hash_bits_per_character) < 4
                     || PS(hash_bits_per_character) > 6) {
              PS(hash_bits_per_character) = 4;

              php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ini setting hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for now");
       }
       
       outid = emalloc((size_t)((digest_len + 2) * ((8.0f / PS(hash_bits_per_character)) + 0.5)));
       j = (int) (bin_to_readable((char *)digest, digest_len, outid, (char)PS(hash_bits_per_character)) - outid);
       efree(digest);

       if (newlen) {
              *newlen = j;
       }

       return outid;
}

Here is the call graph for this function:

Definition at line 1043 of file session.c.

{
       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;
}

Here is the caller graph for this function:

Definition at line 1012 of file session.c.

{
       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;
}
PHPAPI void php_session_set_id ( char *id  TSRMLS_DC)
void php_session_shutdown ( void *  data)

Definition at line 1361 of file session.c.

{
       zval **ppid;
       zval **data;
       char *p, *value;
       int nrand;
       int lensess;

       if (PS(use_only_cookies)) {
              PS(apply_trans_sid) = 0;
       } else {
              PS(apply_trans_sid) = PS(use_trans_sid);
       }

       switch (PS(session_status)) {
              case php_session_active:
                     php_error(E_NOTICE, "A session had already been started - ignoring session_start()");
                     return;
                     break;

              case php_session_disabled:
                     value = zend_ini_string("session.save_handler", sizeof("session.save_handler"), 0);
                     if (!PS(mod) && value) {
                            PS(mod) = _php_find_ps_module(value TSRMLS_CC);
                            if (!PS(mod)) {
                                   php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find save handler '%s' - session startup failed", value);
                                   return;
                            }
                     }
                     value = zend_ini_string("session.serialize_handler", sizeof("session.serialize_handler"), 0);
                     if (!PS(serializer) && value) {
                            PS(serializer) = _php_find_ps_serializer(value TSRMLS_CC);
                            if (!PS(serializer)) {
                                   php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find serialization handler '%s' - session startup failed", value);
                                   return;
                            }
                     }
                     PS(session_status) = php_session_none;
                     /* fallthrough */

              default:
              case php_session_none:
                     PS(define_sid) = 1;
                     PS(send_cookie) = 1;
       }

       lensess = strlen(PS(session_name));

       /* Cookies are preferred, because initially
        * cookie and get variables will be available. */

       if (!PS(id)) {
              if (PS(use_cookies) && zend_hash_find(&EG(symbol_table), "_COOKIE", sizeof("_COOKIE"), (void **) &data) == SUCCESS &&
                            Z_TYPE_PP(data) == IS_ARRAY &&
                            zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS
              ) {
                     PPID2SID;
                     PS(apply_trans_sid) = 0;
                     PS(send_cookie) = 0;
                     PS(define_sid) = 0;
              }

              if (!PS(use_only_cookies) && !PS(id) &&
                            zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void **) &data) == SUCCESS &&
                            Z_TYPE_PP(data) == IS_ARRAY &&
                            zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS
              ) {
                     PPID2SID;
                     PS(send_cookie) = 0;
              }

              if (!PS(use_only_cookies) && !PS(id) &&
                            zend_hash_find(&EG(symbol_table), "_POST", sizeof("_POST"), (void **) &data) == SUCCESS &&
                            Z_TYPE_PP(data) == IS_ARRAY &&
                            zend_hash_find(Z_ARRVAL_PP(data), PS(session_name), lensess + 1, (void **) &ppid) == SUCCESS
              ) {
                     PPID2SID;
                     PS(send_cookie) = 0;
              }
       }

       /* 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 */

       if (!PS(use_only_cookies) && !PS(id) && PG(http_globals)[TRACK_VARS_SERVER] &&
                     zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
                     Z_TYPE_PP(data) == IS_STRING &&
                     (p = strstr(Z_STRVAL_PP(data), PS(session_name))) &&
                     p[lensess] == '='
       ) {
              char *q;

              p += lensess + 1;
              if ((q = strpbrk(p, "/?\\"))) {
                     PS(id) = estrndup(p, q - p);
                     PS(send_cookie) = 0;
              }
       }

       /* Check whether the current request was referred to by
        * an external site which invalidates the previously found id. */

       if (PS(id) &&
                     PS(extern_referer_chk)[0] != '\0' &&
                     PG(http_globals)[TRACK_VARS_SERVER] &&
                     zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_REFERER", sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
                     Z_TYPE_PP(data) == IS_STRING &&
                     Z_STRLEN_PP(data) != 0 &&
                     strstr(Z_STRVAL_PP(data), PS(extern_referer_chk)) == NULL
       ) {
              efree(PS(id));
              PS(id) = NULL;
              PS(send_cookie) = 1;
              if (PS(use_trans_sid) && !PS(use_only_cookies)) {
                     PS(apply_trans_sid) = 1;
              }
       }

       php_session_initialize(TSRMLS_C);

       if (!PS(use_cookies) && PS(send_cookie)) {
              if (PS(use_trans_sid) && !PS(use_only_cookies)) {
                     PS(apply_trans_sid) = 1;
              }
              PS(send_cookie) = 0;
       }

       php_session_reset_id(TSRMLS_C);

       PS(session_status) = php_session_active;

       php_session_cache_limiter(TSRMLS_C);

       if (PS(mod_data) && PS(gc_probability) > 0) {
              int nrdels = -1;

              nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg(TSRMLS_C));
              if (nrand < PS(gc_probability)) {
                     PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels TSRMLS_CC);
#ifdef SESSION_DEBUG
                     if (nrdels != -1) {
                            php_error_docref(NULL TSRMLS_CC, E_NOTICE, "purged %d expired session objects", nrdels);
                     }
#endif
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_set_session_var ( char *  name,
size_t  namelen,
zval *  state_val,
php_unserialize_data_t *var_hash  TSRMLS_DC 
)

Definition at line 171 of file session.c.

{
       if (PG(register_globals)) {
              zval **old_symbol;
              if (zend_hash_find(&EG(symbol_table),name,namelen+1,(void *)&old_symbol) == SUCCESS) {
                     if ((Z_TYPE_PP(old_symbol) == IS_ARRAY && Z_ARRVAL_PP(old_symbol) == &EG(symbol_table)) || *old_symbol == PS(http_session_vars)) {
                            return;
                     }

                     /* A global symbol with the same name exists already. That
                      * symbol might have been created by other means (e.g. $_GET).
                      *
                      * 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.
                      *
                      * BTW: if you use register_globals references between
                      * session-vars won't work because of this very reason! */

                     REPLACE_ZVAL_VALUE(old_symbol,state_val,1);

                     /* The following line will update the reference table used for
                      * unserialization.  It is optional, because some storage
                      * formats may not be able to represent references. */

                     if (var_hash) {
                            PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash,state_val,*old_symbol);
                     }

                     zend_set_hash_symbol(*old_symbol, name, namelen, 1, 1, Z_ARRVAL_P(PS(http_session_vars)));
              } else {
                     zend_set_hash_symbol(state_val, name, namelen, 1, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table));
              }
       } else IF_SESSION_VARS() {
              zend_set_hash_symbol(state_val, name, namelen, PZVAL_IS_REF(state_val), 1, Z_ARRVAL_P(PS(http_session_vars)));
       }
}

Here is the call graph for this function:

PHPAPI void session_adapt_url ( const char *  ,
size_t  ,
char **  ,
size_t TSRMLS_DC 
)

Variable Documentation

zend_module_entry session_module_entry

Definition at line 2290 of file session.c.