svn: /phpdoc/en/trunk/reference/session/ examples.xml

From: Date: Mon, 12 Mar 2012 19:13:43 +0000
Subject: svn: /phpdoc/en/trunk/reference/session/ examples.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9865@lists.php.net to get a copy of this message
drak Mon, 12 Mar 2012 19:13:43 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=324166 Log: [sessions] Begin cleanup of the basic introduction to sessions. Changed paths: U phpdoc/en/trunk/reference/session/examples.xml Modified: phpdoc/en/trunk/reference/session/examples.xml =================================================================== --- phpdoc/en/trunk/reference/session/examples.xml 2012-03-12 18:08:34 UTC (rev 324165) +++ phpdoc/en/trunk/reference/session/examples.xml 2012-03-12 19:13:43 UTC (rev 324166) @@ -7,40 +7,38 @@ <title>Basic usage</title> <note> <para> - As of PHP 4.1.0, <varname>$_SESSION</varname> is available as a - global variable just like <varname>$_POST</varname>, - <varname>$_GET</varname>, <varname>$_REQUEST</varname> and so on. - Unlike <varname>$HTTP_SESSION_VARS</varname>, - <varname>$_SESSION</varname> is always global. Therefore, you do not - need to use the <link - linkend="language.variables.scope"><command>global</command></link> - keyword for <varname>$_SESSION</varname>. Please note that this - documentation has been changed to use - <varname>$_SESSION</varname> everywhere. You can substitute - <varname>$HTTP_SESSION_VARS</varname> for - <varname>$_SESSION</varname>, if you prefer the former. Also note - that you must start your session using <function>session_start</function> - before use of <varname>$_SESSION</varname> becomes available. + Sessions are a simple way to store data for individual users against a unique session ID. + This can be used to persist state information between page requests. Session IDs are normally + sent to the browser via session cookies and the ID is used to retrieve existing session data. + The absence of a ID or session cookie let's PHP know to create a new session, and generate a new + session ID. </para> <para> - The keys in the <varname>$_SESSION</varname> associative - array are subject to the - same limitations as regular variable names in PHP, i.e. they cannot - start with a number and must start with a letter or underscore. - For more details see the section on - <link linkend="language.variables">variables</link> in this manual. + Sessions follow a simple workflow. When a session is started, PHP will either retrieve an + existing session using the ID passed (usually from a session cookie) or if no session is passed + it will create a new session. PHP will populate the <varname>$_SESSION</varname> superglobal + with any session data after the session has started. When PHP shuts down, it will automatically + take the contents of the <varname>$_SESSION</varname> superglobal, serialize it, and send it + for storage using the session save handler. </para> + <para> + By default, PHP uses the internal <parameter>files</parameter> save handler which + is set by <link linkend="ini.session.save-handler">session.save_handler</link>. + This saves session data on the server at the location specified by the + <link linkend="ini.session.save-path">session.save_path</link> configuration directive. + </para> + <para> + Sessions can be started manually using the <function>session_start</function> function, + and if the <link linkend="ini.session.auto-start">session.auto_start</link> directive is set + to <parameter>1</parameter>, a session will automatically start the moment PHP sends any output + to the output buffer. + </para> + <para> + Sessions normally shutdown automatically when PHP is finished executing a script, but can be + manually shutdown using the <function>session_write_close</function> function. + </para> </note> - <para> - If <link - linkend="ini.register-globals">register_globals</link> - is disabled, only members of the global associative array - <varname>$_SESSION</varname> can be registered as session - variables. The restored session variables will only be available - in the array <varname>$_SESSION</varname>. - </para> - <para> Use of <varname>$_SESSION</varname> (or <varname>$HTTP_SESSION_VARS</varname> with PHP 4.0.6 or less) is recommended for improved security and code readability. With @@ -57,7 +55,6 @@ <![CDATA[ <?php session_start(); -// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less if (!isset($_SESSION['count'])) { $_SESSION['count'] = 0; } else { @@ -77,7 +74,6 @@ <![CDATA[ <?php session_start(); -// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less unset($_SESSION['count']); ?> ]]> @@ -110,18 +106,6 @@ variables with <function>session_register</function> function. You can avoid this by simply setting entries in <varname>$_SESSION</varname>. - <caution> - <para> - Before PHP 4.3.0, if you are using <varname>$_SESSION</varname> and you - have disabled <link linkend="ini.register-globals">register_globals</link>, - don't use <function>session_register</function>, - <function>session_is_registered</function> or - <function>session_unregister</function>. - Disabling <link - linkend="ini.register-globals">register_globals</link> - is recommended for both security and performance reasons. - </para> - </caution> </para> <para> If <link @@ -132,15 +116,6 @@ However, if the variable is registered by <varname>$_SESSION</varname> then the global variable is available since the next request. </para> - <para> - There is a defect in PHP 4.2.3 and earlier. If you register a new - session variable by using <function>session_register</function>, the - entry in the global scope and the <varname>$_SESSION</varname> entry will - not reference the same value until the next - <function>session_start</function>. I.e. a modification to the newly - registered global variable will not be reflected by the - <varname>$_SESSION</varname> entry. This has been corrected in PHP 4.3.0. - </para> </section> <section xml:id="session.idpassing"> @@ -200,9 +175,9 @@ session_start(); if (empty($_SESSION['count'])) { - $_SESSION['count'] = 1; + $_SESSION['count'] = 1; } else { - $_SESSION['count']++; + $_SESSION['count']++; } ?>

« previous php.doc.cvs (#9865) next »