Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Static class members (or any other variables for that matter) are not preserved across different requests. Never.</p> <h2>Sessions to the rescue</h2> <p>The only exception to this is <code>$_SESSION</code>; which is a special mechanism to allow for just that.</p> <p>Star the session with <a href="http://www.php.net/manual/en/function.session-start.php" rel="nofollow"><code>session_start()</code></a> at the top of your script.</p> <p>You can now use <code>$_SESSION</code> like a regular array to store and retrieve information. A session belongs to a single user, it is not a means of sharing data across all your users.</p> <p>Have a look <a href="http://www.php.net/manual/en/session.examples.basic.php" rel="nofollow">here</a> for an introduction.</p> <h2>Silence</h2> <p>You must not output anything before <code>session_start()</code> is called. That is to say, <code>&lt;?php</code> must be the exact first thing in a PHP script that wishes to use sessions. Further, there must be no echo statements or any other output generating functions between <code>&lt;?php</code> and <code>session_start()</code>.</p> <h2>Output Buffering</h2> <p>If you really must generate output before starting the session, you can use <a href="http://php.net/manual/en/function.ob-start.php" rel="nofollow">output buffering</a>.</p> <h2>Notes</h2> <ul> <li><code>$_SESSION</code> is forgetful. After a certain <a href="http://www.php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime" rel="nofollow">time</a> of inactivity on the user's side, the data will be deleted.</li> <li>If you get the following error message, you violated the above guidelines. Another possibility is that your script has a BOM (Unicode byte order mark). If so, remove it.</li> </ul> <blockquote> <p>Warning: session_start(): Cannot send session cookie - headers already sent by (output started at</p> </blockquote> <p>The reason this happens is due to the way PHP handles output: It tries to get the output as fast as possible to the user. However, the HTTP protocol transmits certain control data (cookies, which session belongs to you etc), called "headers" before all the output ("body") of the response. As soon as you output anything, the headers need to get sent - unless you use output buffering that is.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload