PageRenderTime 47ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/phpMyAdmin/libraries/session.inc.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 112 lines | 46 code | 17 blank | 49 comment | 12 complexity | 5b5af7d62312b2510e94d86b75117606 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * session handling
  5. *
  6. * @todo add failover or warn if sessions are not configured properly
  7. * @todo add an option to use mm-module for session handler
  8. * @see http://www.php.net/session
  9. * @package PhpMyAdmin
  10. */
  11. if (! defined('PHPMYADMIN')) {
  12. exit;
  13. }
  14. // verify if PHP supports session, die if it does not
  15. if (!@function_exists('session_name')) {
  16. PMA_warnMissingExtension('session', true);
  17. } elseif (ini_get('session.auto_start') == true && session_name() != 'phpMyAdmin') {
  18. // Do not delete the existing session, it might be used by other
  19. // applications; instead just close it.
  20. session_write_close();
  21. }
  22. // disable starting of sessions before all settings are done
  23. // does not work, besides how it is written in php manual
  24. //ini_set('session.auto_start', 0);
  25. // session cookie settings
  26. session_set_cookie_params(0, $GLOBALS['PMA_Config']->getCookiePath(),
  27. '', $GLOBALS['PMA_Config']->isHttps(), true);
  28. // cookies are safer (use @ini_set() in case this function is disabled)
  29. @ini_set('session.use_cookies', true);
  30. // optionally set session_save_path
  31. $path = $GLOBALS['PMA_Config']->get('SessionSavePath');
  32. if (!empty($path)) {
  33. session_save_path($path);
  34. }
  35. // but not all user allow cookies
  36. @ini_set('session.use_only_cookies', false);
  37. // do not force transparent session ids, see bug #3398788
  38. //@ini_set('session.use_trans_sid', true);
  39. @ini_set('url_rewriter.tags',
  40. 'a=href,frame=src,input=src,form=fakeentry,fieldset=');
  41. //ini_set('arg_separator.output', '&amp;');
  42. // delete session/cookies when browser is closed
  43. @ini_set('session.cookie_lifetime', 0);
  44. // warn but dont work with bug
  45. @ini_set('session.bug_compat_42', false);
  46. @ini_set('session.bug_compat_warn', true);
  47. // use more secure session ids
  48. @ini_set('session.hash_function', 1);
  49. // some pages (e.g. stylesheet) may be cached on clients, but not in shared
  50. // proxy servers
  51. session_cache_limiter('private');
  52. // start the session
  53. // on some servers (for example, sourceforge.net), we get a permission error
  54. // on the session data directory, so I add some "@"
  55. // See bug #1538132. This would block normal behavior on a cluster
  56. //ini_set('session.save_handler', 'files');
  57. $session_name = 'phpMyAdmin';
  58. @session_name($session_name);
  59. if (! isset($_COOKIE[$session_name])) {
  60. // on first start of session we check for errors
  61. // f.e. session dir cannot be accessed - session file not created
  62. $orig_error_count = $GLOBALS['error_handler']->countErrors();
  63. $r = session_start();
  64. if ($r !== true || $orig_error_count != $GLOBALS['error_handler']->countErrors()) {
  65. setcookie($session_name, '', 1);
  66. /*
  67. * Session initialization is done before selecting language, so we
  68. * can not use translations here.
  69. */
  70. PMA_fatalError('Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.');
  71. }
  72. unset($orig_error_count);
  73. } else {
  74. session_start();
  75. }
  76. /**
  77. * Token which is used for authenticating access queries.
  78. * (we use "space PMA_token space" to prevent overwriting)
  79. */
  80. if (! isset($_SESSION[' PMA_token '])) {
  81. $_SESSION[' PMA_token '] = md5(uniqid(rand(), true));
  82. }
  83. /**
  84. * tries to secure session from hijacking and fixation
  85. * should be called before login and after successfull login
  86. * (only required if sensitive information stored in session)
  87. *
  88. */
  89. function PMA_secureSession()
  90. {
  91. // prevent session fixation and XSS
  92. session_regenerate_id(true);
  93. $_SESSION[' PMA_token '] = md5(uniqid(rand(), true));
  94. }
  95. ?>