home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / session.inc.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  4.0 KB  |  129 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * session handling
  5.  *
  6.  * @version $Id: session.inc.php 11326 2008-06-17 21:32:48Z lem9 $
  7.  * @todo    add failover or warn if sessions are not configured properly
  8.  * @todo    add an option to use mm-module for session handler
  9.  * @see     http://www.php.net/session
  10.  * @uses    session_name()
  11.  * @uses    session_start()
  12.  * @uses    ini_set()
  13.  * @uses    version_compare()
  14.  * @uses    PHP_VERSION
  15.  */
  16. if (! defined('PHPMYADMIN')) {
  17.     exit;
  18. }
  19.  
  20. // verify if PHP supports session, die if it does not
  21.  
  22. if (!@function_exists('session_name')) {
  23.     PMA_fatalError('strCantLoad', 'session');
  24. } elseif (ini_get('session.auto_start') == true && session_name() != 'phpMyAdmin') {
  25.     // Do not delete the existing session, it might be used by other 
  26.     // applications; instead just close it.
  27.     session_write_close();
  28. }
  29.  
  30. // disable starting of sessions before all settings are done
  31. // does not work, besides how it is written in php manual
  32. //ini_set('session.auto_start', 0);
  33.  
  34. // session cookie settings
  35. session_set_cookie_params(0, PMA_Config::getCookiePath() . '; HttpOnly',
  36.     '', PMA_Config::isHttps());
  37.  
  38. // cookies are safer
  39. ini_set('session.use_cookies', true);
  40.  
  41. // but not all user allow cookies
  42. ini_set('session.use_only_cookies', false);
  43. ini_set('session.use_trans_sid', true);
  44. ini_set('url_rewriter.tags',
  45.     'a=href,frame=src,input=src,form=fakeentry,fieldset=');
  46. //ini_set('arg_separator.output', '&');
  47.  
  48. // delete session/cookies when browser is closed
  49. ini_set('session.cookie_lifetime', 0);
  50.  
  51. // warn but dont work with bug
  52. ini_set('session.bug_compat_42', false);
  53. ini_set('session.bug_compat_warn', true);
  54.  
  55. // use more secure session ids (with PHP 5)
  56. if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
  57.     ini_set('session.hash_function', 1);
  58. }
  59.  
  60. // some pages (e.g. stylesheet) may be cached on clients, but not in shared
  61. // proxy servers
  62. session_cache_limiter('private');
  63.  
  64. // start the session
  65. // on some servers (for example, sourceforge.net), we get a permission error
  66. // on the session data directory, so I add some "@"
  67.  
  68. // See bug #1538132. This would block normal behavior on a cluster
  69. //ini_set('session.save_handler', 'files');
  70.  
  71. $session_name = 'phpMyAdmin';
  72. @session_name($session_name);
  73. // strictly, PHP 4 since 4.4.2 would not need a verification
  74. if (version_compare(PHP_VERSION, '5.1.2', 'lt')
  75.  && isset($_COOKIE[$session_name])
  76.  && eregi("\r|\n", $_COOKIE[$session_name])) {
  77.     die('attacked');
  78. }
  79.  
  80. if (! isset($_COOKIE[$session_name])) {
  81.     // on first start of session we will check for errors
  82.     // f.e. session dir cannot be accessed - session file not created
  83.     ob_start();
  84.     $old_display_errors = ini_get('display_errors');
  85.     $old_error_reporting = error_reporting(E_ALL);
  86.     ini_set('display_errors', 1);
  87.     $r = session_start();
  88.     ini_set('display_errors', $old_display_errors);
  89.     error_reporting($old_error_reporting);
  90.     unset($old_display_errors, $old_error_reporting);
  91.     $session_error = ob_get_contents();
  92.     ob_end_clean();
  93.     if ($r !== true || ! empty($session_error)) {
  94.         setcookie($session_name, '', 1);
  95.         PMA_fatalError('strSessionStartupErrorGeneral');
  96.     }
  97. } else {
  98.     @session_start();
  99. }
  100.  
  101. /**
  102.  * Token which is used for authenticating access queries.
  103.  * (we use "space PMA_token space" to prevent overwriting)
  104.  */
  105. if (!isset($_SESSION[' PMA_token '])) {
  106.     $_SESSION[' PMA_token '] = md5(uniqid(rand(), true));
  107. }
  108.  
  109. /**
  110.  * tries to secure session from hijacking and fixation
  111.  * should be called before login and after successfull login
  112.  * (only required if sensitive information stored in session)
  113.  *
  114.  * @uses    session_regenerate_id() to secure session from fixation
  115.  * @uses    session_id()            to set new session id
  116.  * @uses    strip_tags()            to prevent XSS attacks in SID
  117.  * @uses    function_exists()       for session_regenerate_id()
  118.  */
  119. function PMA_secureSession()
  120. {
  121.     // prevent session fixation and XSS
  122.     if (function_exists('session_regenerate_id')) {
  123.         session_regenerate_id(true);
  124.     } else {
  125.         session_id(strip_tags(session_id()));
  126.     }
  127. }
  128. ?>
  129.