What are some guidelines for maintaining responsible session security with PHP? There's information all over the web and it's about time it all landed in one place!
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
php.ini
eq Apache add header:
I think one of the major problems (which is being addressed in PHP 6) is register_globals. Right now one of the standard methods used to avoid
register_globals
is to use the$_REQUEST
,$_GET
or$_POST
arrays.The "correct" way to do it (as of 5.2, although it's a little buggy there, but stable as of 6, which is coming soon) is through filters.
So instead of:
you would do:
or even just:
You need to be sure the session data are safe. By looking at your php.ini or using phpinfo() you can find you session settings. _session.save_path_ tells you where they are saved.
Check the permission of the folder and of its parents. It shouldn't be public (/tmp) or be accessible by other websites on your shared server.
Assuming you still want to use php session, You can set php to use an other folder by changing _session.save_path_ or save the data in the database by changing _session.save_handler_ .
You might be able to set _session.save_path_ in your php.ini (some providers allow it) or for apache + mod_php, in a .htaccess file in your site root folder:
php_value session.save_path "/home/example.com/html/session"
. You can also set it at run time with _session_save_path()_ .Check Chris Shiflett's tutorial or Zend_Session_SaveHandler_DbTable to set and alternative session handler.
This session fixation paper has very good pointers where attack may come. See also session fixation page at Wikipedia.
I set my sessions up like this-
on the log in page:
(phrase defined on a config page)
then on the header that is throughout the rest of the site:
I would check both IP and User Agent to see if they change