预定义常量

下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。

SID (string)
包含着会话名以及会话 ID 的常量,格式为 "name=ID",或者如果会话 ID 已经在适当的会话 cookie 中设定时则为空字符串。 这和 session_id() 返回的是同一个 ID。
PHP_SESSION_DISABLED (int)
自 PHP 5.4.0 起。如果会话已禁用则返回 session_status() 的值。
PHP_SESSION_NONE (int)
自 PHP 5.4.0 起。在会话已启用但是没有会话的时候返回 session_status() 的值。
PHP_SESSION_ACTIVE (int)
自 PHP 5.4.0 起。在一个会话已启用并存在时返回 session_status() 的值。

User Contributed Notes

sarath dot jasrin at gmail dot com 12-Oct-2016 09:05
Check whether session started using Predefined Constants

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
Anonymous 15-Aug-2016 03:12
SID constant defined dynamically!

var_dump(defined('SID'));  // bool(false) - Not defined...
session_start();
var_dump(defined('SID'));  // bool(true) - Defined now!
yesmarklapointe at hotmail dot com 05-Feb-2009 01:19
Here is some info about how to use SID. Experiment run on WAMPserver, PHP version 5.2.6.
Using FireFox 3.0.

In php.ini,  session.use_cookies has an effect upon whether or not SID passes an empty string or the session info. If it is on, SID is evaluated for the session info upon initial page view, but once a cookie has been set (automatically by  session.use_cookies) in the browser, subsequent views (like page reloads or using the back button) have the cookie being returned to the script so SID is then evaluated as an empty string. On the other hand, if session.use_cookies is off, (and provided you don't create a cookie by some other means), SID will evaluate as the session info no matter how many times you reload the page or use the back button because session_start() keeps opening a new session and no cookies are being set. Be aware this behavior will change the functionality of any links you build with SID. To have a reliable link with session info in it, spell it out using session_name() and session_id(), not SID. Example:

echo '<a href="page2.php?' . session_name() . ' ='  . session_id() . ' ">page2</a>' ;

and not

echo '<a href="page2.php?' . SID . ' ">page2</a>';

Two other settings that I thought might be relevant were not.  session.use_only_cookies  and session.use_trans_sid have no effect at all on the evaluation of SID for a specific line in the code, that is, in  regard to whether or not it is evaluated as an empty string or as the session info. 

And as to functioning in your code, using both session.use_trans_sid and also successfully evaluating SID for session info (as described above) will create a doubling of the session info, screwing up the path you are trying to create.