Which is the best way or method to prevent session fixation and highjacking in php ? [closed]
I browsed various method to prevent session fixation and highjacking in php but I am finding it difficult to figure out which is the best way on which I can rely on . Like to prevent sql injection most of the developer suggest use of prepare statement .It is effective in preventing most of the sql injection attacks . Is there any such code , function or snippet availble best,quick and simple in regard to prevent attack on session . Please share it . Thank you all .
There is a few things you can do to help such as, when setting cookies set them to httponly so they are not able to be read from javascript, keep track of a users ip address and only allow access to the session if the users ip is within a certain range of the ip they started the session with, when starting a new session regenerate session id instead of reusing a previous one , keep track of the users browser and if that changes during a session do not allow access to the session. I am sure there are more but thats just off the top pf my head.
Do not allow http protocol, only https.
That's it, it prevents SESSID hijackings...
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://yourdomain.com/ [R]
精彩评论