]> granicus.if.org Git - php/commitdiff
Expose session status via new function, session_status (Req #52982)
authorArpad Ray <arpad@php.net>
Mon, 29 Aug 2011 21:29:26 +0000 (21:29 +0000)
committerArpad Ray <arpad@php.net>
Mon, 29 Aug 2011 21:29:26 +0000 (21:29 +0000)
NEWS
ext/session/session.c
ext/session/tests/session_status.phpt [new file with mode: 0644]
ext/session/tests/session_status_disabled.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 01285567f9b06172743df6cf220bd4a7cec9e039..32d93a2c5d19d69344ac21aa21126df596d80ad5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -296,6 +296,7 @@ PHP                                                                        NEWS
   . Added support for storing upload progress feedback in session data. (Arnaud)
   . Changed session.entropy_file to default to /dev/urandom or /dev/arandom if
     either is present at compile time. (Rasmus)
+  . Expose session status via new function, session_status (Req #52982) (arpad)
 
 - Improved SPL extension:
   . Added RegexIterator::getRegex() method. (Joshua Thijssen)
index 89a3aca415c985fa02f61b3b5b6451ce66943040..d511a462fe0d1e7adca02c0234f6b848080d9a5f 100644 (file)
@@ -1830,6 +1830,18 @@ static PHP_FUNCTION(session_write_close)
 }
 /* }}} */
 
+/* {{{ proto int session_status(void)
+   Returns the current session status */
+static PHP_FUNCTION(session_status)
+{
+       if (zend_parse_parameters_none() == FAILURE) {
+               return;
+       }
+
+       RETURN_LONG(PS(session_status));
+}
+/* }}} */
+
 /* {{{ arginfo */
 ZEND_BEGIN_ARG_INFO_EX(arginfo_session_name, 0, 0, 0)
        ZEND_ARG_INFO(0, name)
@@ -1903,6 +1915,7 @@ static const zend_function_entry session_functions[] = {
        PHP_FE(session_set_cookie_params, arginfo_session_set_cookie_params)
        PHP_FE(session_get_cookie_params, arginfo_session_void)
        PHP_FE(session_write_close,       arginfo_session_void)
+       PHP_FE(session_status,            arginfo_session_void)
        PHP_FALIAS(session_commit, session_write_close, arginfo_session_void)
        PHP_FE_END
 };
@@ -2004,6 +2017,11 @@ static PHP_MINIT_FUNCTION(session) /* {{{ */
 #endif
        php_session_rfc1867_orig_callback = php_rfc1867_callback;
        php_rfc1867_callback = php_session_rfc1867_callback;
+
+       REGISTER_LONG_CONSTANT("PHP_SESSION_DISABLED", php_session_disabled, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PHP_SESSION_NONE", php_session_none, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PHP_SESSION_ACTIVE", php_session_active, CONST_CS | CONST_PERSISTENT);
+
        return SUCCESS;
 }
 /* }}} */
diff --git a/ext/session/tests/session_status.phpt b/ext/session/tests/session_status.phpt
new file mode 100644 (file)
index 0000000..d1f7e2f
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Test session_status() function : active, none
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+echo "*** Testing session_status() : active, none\n";
+
+var_dump(PHP_SESSION_NONE != PHP_SESSION_ACTIVE);
+var_dump(session_status() == PHP_SESSION_NONE);
+
+session_start();
+
+var_dump(session_status() == PHP_SESSION_ACTIVE);
+
+?>
+--EXPECTF--
+*** Testing session_status() : active, none
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/session/tests/session_status_disabled.phpt b/ext/session/tests/session_status_disabled.phpt
new file mode 100644 (file)
index 0000000..24e0ecd
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Test session_status() function : disabled
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--INI--
+session.save_handler=non-existant
+--FILE--
+<?php
+
+echo "*** Testing session_status() : disabled\n";
+
+var_dump(session_status() == PHP_SESSION_DISABLED);
+
+?>
+--EXPECTF--
+*** Testing session_status() : disabled
+bool(true)