/*
* TODO:
- * - improve session id creation to avoid collisions
- * (make use of mersenne twister, other data such as IP, browser etc.)
* - add complete support for objects (partially implemented)
* - userland callback functions for ps_module
- * - write documentation
* - write ps_module utilizing shared memory (mm)
*/
#if !(WIN32|WINNT)
#include "ext/standard/md5.h"
#include "ext/standard/php3_var.h"
#include "ext/standard/datetime.h"
-
+#include "ext/lcg/php_lcg.h"
#ifdef ZTS
int ps_globals_id;
PHP_INI_ENTRY("session.gc_maxlifetime", "1440", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.lifetime", "0", PHP_INI_ALL, NULL)
PHP_INI_ENTRY("session.serialize_handler", "php", PHP_INI_ALL, NULL)
+ PHP_INI_ENTRY("session.extern_referer_chk", "", PHP_INI_ALL, NULL)
PHP_INI_END()
PS_SERIALIZER_FUNCS(php);
gettimeofday(&tv, NULL);
PHP3_MD5Init(&context);
- sprintf(buf, "%ld%ld", tv.tv_sec, tv.tv_usec);
+ sprintf(buf, "%ld%ld%0.8f", tv.tv_sec, tv.tv_usec, php_combined_lcg() * 10);
PHP3_MD5Update(&context, buf, strlen(buf));
PHP3_MD5Final(digest, &context);
lensess = strlen(PS(session_name));
+ /* check whether a symbol with the name of the session exists
+ in the global symbol table */
+
if(!PS(id) &&
zend_hash_find(&EG(symbol_table), PS(session_name),
lensess + 1, (void **) &ppid) == SUCCESS) {
send_cookie = 0;
}
+ /* if the previous section was successful, we check whether
+ a symbol with the name of the session exists in the global
+ HTTP_COOKIE_VARS array */
+
if(!send_cookie &&
zend_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS",
sizeof("HTTP_COOKIE_VARS"), (void **) &data) == SUCCESS &&
define_sid = 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(id) &&
zend_hash_find(&EG(symbol_table), "REQUEST_URI",
sizeof("REQUEST_URI"), (void **) &data) == SUCCESS &&
if((q = strpbrk(p, "/?\\")))
PS(id) = estrndup(p, q - p);
}
+
+ /* 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' &&
+ zend_hash_find(&EG(symbol_table), "HTTP_REFERER",
+ sizeof("HTTP_REFERER"), (void **) &data) == SUCCESS &&
+ (*data)->type == IS_STRING &&
+ (*data)->value.str.len != 0 &&
+ strstr((*data)->value.str.val, PS(extern_referer_chk)) == NULL) {
+ efree(PS(id));
+ PS(id) = NULL;
+ send_cookie = 1;
+ define_sid = 1;
+ }
if(!PS(id)) {
PS(id) = _php_create_id(NULL);
PS(session_name) = estrdup(INI_STR("session.name"));
PS(gc_probability) = INI_INT("session.gc_probability");
PS(gc_maxlifetime) = INI_INT("session.gc_maxlifetime");
+ PS(extern_referer_chk) = estrdup(INI_STR("extern_referer_chk"));
PS(id) = NULL;
PS(lifetime) = INI_INT("session.lifetime");
PS(nr_open_sessions) = 0;
{
if(PS(mod_data))
PS(mod)->close(&PS(mod_data));
+ efree(PS(extern_referer_chk));
efree(PS(save_path));
efree(PS(session_name));
if(PS(id)) efree(PS(id));