Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Session management changed some time back (I think it was around 4.4). The old mechanism still works, but is deprecated. It's rather confusing, so I recommend staying clear of it. Today, you use sessions by accessing the global variable $_SESSION (It's an array). You <em>can</em> put object instances in there, but you need to load the class definitions for those objects before starting the session on the next page. Using <a href="http://docs.php.net/manual/en/language.oop5.autoload.php" rel="nofollow noreferrer">autoload</a> can help you out here.</p> <p>You must <a href="http://docs.php.net/manual/en/function.session-start.php" rel="nofollow noreferrer">start a session</a> before you can use $_SESSION. Since starting the session sends headers, you can't have any output before. This can be solved in one of two ways: Either you always begin the session at the start of your script. Or you <a href="http://docs.php.net/manual/en/book.outcontrol.php" rel="nofollow noreferrer">buffer all output</a>, and send it out at the end of the script.</p> <blockquote> <p>One good idea is to regenerate the session on each request. this makes hijack much less likely.</p> </blockquote> <p>That's (slightly) bad advice, since it can make the site inaccessible. You should <a href="http://docs.php.net/manual/en/function.session-regenerate-id.php" rel="nofollow noreferrer">regenerate the session-id</a> whenever a users privileges changes though. In general that means, whenever they log in. This is to prevent session-fixation (A form of session-hijacking). See <a href="http://www.sitepoint.com/forums/showthread.php?t=571084" rel="nofollow noreferrer">this recent thread @ Sitepoint</a> for more on the subject.</p> <p>Using cookiebased sessions <em>only</em> is OK, but if you regenerate session id's on login, it doesn't add any additional security, and it lowers accessibility a bit.</p>
 

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