Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some basics about standard sessions (with cookies):<br> When a user visits your site for the first time, <a href="http://php.net/manual/en/function.session-start.php" rel="nofollow noreferrer">session_start</a>() will create<br> a file using a hash as filename (more or less random (<a href="http://svn.php.net/viewvc/php/php-src/trunk/ext/session/session.c?revision=297232&amp;view=markup#l344" rel="nofollow noreferrer">*</a>) (see <a href="http://www.php.net/manual/en/function.session-save-path.php" rel="nofollow noreferrer">session_save_path</a>()).<br> PHP will store all $_SESSION variables within that file. At the same time the user gets a cookie with that hash (session id).<br> Is the user requesting another site (sends the cookie with the session id) PHP will check if the file with that hash exists. If it does, everything within will be read into $_SESSION.</p> <p>Everything the user has contact with, is the hash. As long as you sanitize everything you're writing into $_SESSION (coming from the user), there is no need to check again when reading those values.</p> <hr> <p>All you need to do is, to make it (from your side) as hard as possible to "steal" the session id (..or use it).<br><br></p> <p>A good start is to allow cookies only. Session ids in the URL end up being copy/pasted or cached by search engines</p> <pre><code>ini_set('session.use_cookies' ,1); ini_set('session.use_only_cookies',1); ini_set('session.use_trans_sid' ,0); </code></pre> <p>before session_start() should do it, see <a href="http://php.net/manual/en/session.configuration.php" rel="nofollow noreferrer">Session Configuration</a> for more info.<br><br><br></p> <p>deleting the current session, creating a new one (new hash) forces a possible attacker to act quickly</p> <pre><code>session_regenerate_id(true); </code></pre> <p>after session_start() does exactly that. (<a href="http://php.net/manual/en/function.session-regenerate-id.php" rel="nofollow noreferrer">session_regenerate_id</a>())<br><br><br></p> <p>Saving the users IP (partly) and destroying the session if it changes is another option</p> <pre><code>// first call: $_SESSION['userip'] = $_SERVER['REMOTE_ADDR']; //following calls: if ($_SESSION['userip'] != $_SERVER['REMOTE_ADDR']) { session_destroy(); } </code></pre> <p>You could run into trouble with that one, since there might be some users changing IP quite frequently.. other $_SERVER vars could be used as well ($_SERVER['HTTP_USER_AGENT'] for example). (<a href="http://php.net/manual/en/reserved.variables.php" rel="nofollow noreferrer">Predefined Variables</a>)<br><br><br></p> <p>There are a few other things you can do (crypt the SID so people wont know the filename, HTTPS is always nice, ..) but that should get you started. Google will certainly find some nice tutorials on "<a href="http://www.google.com/search?hl=en&amp;q=session+security" rel="nofollow noreferrer">session security</a>".</p> <p>Edit: fixed Links.</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. 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