[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/download/ -> file.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package phpBB3
   5  * @version $Id$
   6  * @copyright (c) 2005 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  define('IN_PHPBB', true);
  15  $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
  16  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17  
  18  
  19  // Thank you sun.
  20  if (isset($_SERVER['CONTENT_TYPE']))
  21  {
  22      if ($_SERVER['CONTENT_TYPE'] === 'application/x-java-archive')
  23      {
  24          exit;
  25      }
  26  }
  27  else if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Java') !== false)
  28  {
  29      exit;
  30  }
  31  
  32  if (isset($_GET['avatar']))
  33  {
  34      require($phpbb_root_path . 'includes/startup.' . $phpEx);
  35      require($phpbb_root_path . 'config.' . $phpEx);
  36  
  37      if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
  38      {
  39          exit;
  40      }
  41  
  42      require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
  43      require($phpbb_root_path . 'includes/cache.' . $phpEx);
  44      require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
  45      require($phpbb_root_path . 'includes/constants.' . $phpEx);
  46      require($phpbb_root_path . 'includes/functions.' . $phpEx);
  47  
  48      $db = new $sql_db();
  49      $cache = new cache();
  50  
  51      // Connect to DB
  52      if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false))
  53      {
  54          exit;
  55      }
  56      unset($dbpasswd);
  57  
  58      // worst-case default
  59      $browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';
  60  
  61      $config = $cache->obtain_config();
  62      $filename = request_var('avatar', '');
  63      $avatar_group = false;
  64      $exit = false;
  65  
  66      if (isset($filename[0]) && $filename[0] === 'g')
  67      {
  68          $avatar_group = true;
  69          $filename = substr($filename, 1);
  70      }
  71  
  72      // '==' is not a bug - . as the first char is as bad as no dot at all
  73      if (strpos($filename, '.') == false)
  74      {
  75          send_status_line(403, 'Forbidden');
  76          $exit = true;
  77      }
  78  
  79      if (!$exit)
  80      {
  81          $ext        = substr(strrchr($filename, '.'), 1);
  82          $stamp        = (int) substr(stristr($filename, '_'), 1);
  83          $filename    = (int) $filename;
  84          $exit = set_modified_headers($stamp, $browser);
  85      }
  86      if (!$exit && !in_array($ext, array('png', 'gif', 'jpg', 'jpeg')))
  87      {
  88          // no way such an avatar could exist. They are not following the rules, stop the show.
  89          send_status_line(403, 'Forbidden');
  90          $exit = true;
  91      }
  92  
  93  
  94      if (!$exit)
  95      {
  96          if (!$filename)
  97          {
  98              // no way such an avatar could exist. They are not following the rules, stop the show.
  99              send_status_line(403, 'Forbidden');
 100          }
 101          else
 102          {
 103              send_avatar_to_browser(($avatar_group ? 'g' : '') . $filename . '.' . $ext, $browser);
 104          }
 105      }
 106      file_gc();
 107  }
 108  
 109  // implicit else: we are not in avatar mode
 110  include($phpbb_root_path . 'common.' . $phpEx);
 111  
 112  $download_id = request_var('id', 0);
 113  $mode = request_var('mode', '');
 114  $thumbnail = request_var('t', false);
 115  
 116  // Start session management, do not update session page.
 117  $user->session_begin(false);
 118  $auth->acl($user->data);
 119  $user->setup('viewtopic');
 120  
 121  if (!$download_id)
 122  {
 123      send_status_line(404, 'Not Found');
 124      trigger_error('NO_ATTACHMENT_SELECTED');
 125  }
 126  
 127  if (!$config['allow_attachments'] && !$config['allow_pm_attach'])
 128  {
 129      send_status_line(404, 'Not Found');
 130      trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
 131  }
 132  
 133  $sql = 'SELECT attach_id, in_message, post_msg_id, extension, is_orphan, poster_id, filetime
 134      FROM ' . ATTACHMENTS_TABLE . "
 135      WHERE attach_id = $download_id";
 136  $result = $db->sql_query_limit($sql, 1);
 137  $attachment = $db->sql_fetchrow($result);
 138  $db->sql_freeresult($result);
 139  
 140  if (!$attachment)
 141  {
 142      send_status_line(404, 'Not Found');
 143      trigger_error('ERROR_NO_ATTACHMENT');
 144  }
 145  
 146  if ((!$attachment['in_message'] && !$config['allow_attachments']) || ($attachment['in_message'] && !$config['allow_pm_attach']))
 147  {
 148      send_status_line(404, 'Not Found');
 149      trigger_error('ATTACHMENT_FUNCTIONALITY_DISABLED');
 150  }
 151  
 152  $row = array();
 153  
 154  if ($attachment['is_orphan'])
 155  {
 156      // We allow admins having attachment permissions to see orphan attachments...
 157      $own_attachment = ($auth->acl_get('a_attach') || $attachment['poster_id'] == $user->data['user_id']) ? true : false;
 158  
 159      if (!$own_attachment || ($attachment['in_message'] && !$auth->acl_get('u_pm_download')) || (!$attachment['in_message'] && !$auth->acl_get('u_download')))
 160      {
 161          send_status_line(404, 'Not Found');
 162          trigger_error('ERROR_NO_ATTACHMENT');
 163      }
 164  
 165      // Obtain all extensions...
 166      $extensions = $cache->obtain_attach_extensions(true);
 167  }
 168  else
 169  {
 170      if (!$attachment['in_message'])
 171      {
 172          //
 173          $sql = 'SELECT p.forum_id, f.forum_name, f.forum_password, f.parent_id
 174              FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f
 175              WHERE p.post_id = ' . $attachment['post_msg_id'] . '
 176                  AND p.forum_id = f.forum_id';
 177          $result = $db->sql_query_limit($sql, 1);
 178          $row = $db->sql_fetchrow($result);
 179          $db->sql_freeresult($result);
 180  
 181          // Global announcement?
 182          $f_download = (!$row) ? $auth->acl_getf_global('f_download') : $auth->acl_get('f_download', $row['forum_id']);
 183  
 184          if ($auth->acl_get('u_download') && $f_download)
 185          {
 186              if ($row && $row['forum_password'])
 187              {
 188                  // Do something else ... ?
 189                  login_forum_box($row);
 190              }
 191          }
 192          else
 193          {
 194              send_status_line(403, 'Forbidden');
 195              trigger_error('SORRY_AUTH_VIEW_ATTACH');
 196          }
 197      }
 198      else
 199      {
 200          $row['forum_id'] = false;
 201          if (!$auth->acl_get('u_pm_download'))
 202          {
 203              send_status_line(403, 'Forbidden');
 204              trigger_error('SORRY_AUTH_VIEW_ATTACH');
 205          }
 206  
 207          // Check if the attachment is within the users scope...
 208          $sql = 'SELECT user_id, author_id
 209              FROM ' . PRIVMSGS_TO_TABLE . '
 210              WHERE msg_id = ' . $attachment['post_msg_id'];
 211          $result = $db->sql_query($sql);
 212  
 213          $allowed = false;
 214          while ($user_row = $db->sql_fetchrow($result))
 215          {
 216              if ($user->data['user_id'] == $user_row['user_id'] || $user->data['user_id'] == $user_row['author_id'])
 217              {
 218                  $allowed = true;
 219                  break;
 220              }
 221          }
 222          $db->sql_freeresult($result);
 223  
 224          if (!$allowed)
 225          {
 226              send_status_line(403, 'Forbidden');
 227              trigger_error('ERROR_NO_ATTACHMENT');
 228          }
 229      }
 230  
 231      // disallowed?
 232      $extensions = array();
 233      if (!extension_allowed($row['forum_id'], $attachment['extension'], $extensions))
 234      {
 235          send_status_line(404, 'Forbidden');
 236          trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
 237      }
 238  }
 239  
 240  if (!download_allowed())
 241  {
 242      send_status_line(403, 'Forbidden');
 243      trigger_error($user->lang['LINKAGE_FORBIDDEN']);
 244  }
 245  
 246  $download_mode = (int) $extensions[$attachment['extension']]['download_mode'];
 247  
 248  // Fetching filename here to prevent sniffing of filename
 249  $sql = 'SELECT attach_id, is_orphan, in_message, post_msg_id, extension, physical_filename, real_filename, mimetype, filetime
 250      FROM ' . ATTACHMENTS_TABLE . "
 251      WHERE attach_id = $download_id";
 252  $result = $db->sql_query_limit($sql, 1);
 253  $attachment = $db->sql_fetchrow($result);
 254  $db->sql_freeresult($result);
 255  
 256  if (!$attachment)
 257  {
 258      send_status_line(404, 'Not Found');
 259      trigger_error('ERROR_NO_ATTACHMENT');
 260  }
 261  
 262  $attachment['physical_filename'] = utf8_basename($attachment['physical_filename']);
 263  $display_cat = $extensions[$attachment['extension']]['display_cat'];
 264  
 265  if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg'))
 266  {
 267      $display_cat = ATTACHMENT_CATEGORY_NONE;
 268  }
 269  
 270  if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash'))
 271  {
 272      $display_cat = ATTACHMENT_CATEGORY_NONE;
 273  }
 274  
 275  if ($thumbnail)
 276  {
 277      $attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
 278  }
 279  else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHMENT_CATEGORY_IMAGE*/) && !$attachment['is_orphan'])
 280  {
 281      // Update download count
 282      $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 283          SET download_count = download_count + 1
 284          WHERE attach_id = ' . $attachment['attach_id'];
 285      $db->sql_query($sql);
 286  }
 287  
 288  if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && (strpos(strtolower($user->browser), 'msie') !== false) && !phpbb_is_greater_ie_version($user->browser, 7))
 289  {
 290      wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);
 291      file_gc();
 292  }
 293  else
 294  {
 295      // Determine the 'presenting'-method
 296      if ($download_mode == PHYSICAL_LINK)
 297      {
 298          // This presenting method should no longer be used
 299          if (!@is_dir($phpbb_root_path . $config['upload_path']))
 300          {
 301              send_status_line(500, 'Internal Server Error');
 302              trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
 303          }
 304  
 305          redirect($phpbb_root_path . $config['upload_path'] . '/' . $attachment['physical_filename']);
 306          file_gc();
 307      }
 308      else
 309      {
 310          send_file_to_browser($attachment, $config['upload_path'], $display_cat);
 311          file_gc();
 312      }
 313  }
 314  
 315  
 316  /**
 317  * A simplified function to deliver avatars
 318  * The argument needs to be checked before calling this function.
 319  */
 320  function send_avatar_to_browser($file, $browser)
 321  {
 322      global $config, $phpbb_root_path;
 323  
 324      $prefix = $config['avatar_salt'] . '_';
 325      $image_dir = $config['avatar_path'];
 326  
 327      // Adjust image_dir path (no trailing slash)
 328      if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\')
 329      {
 330          $image_dir = substr($image_dir, 0, -1) . '/';
 331      }
 332      $image_dir = str_replace(array('../', '..\\', './', '.\\'), '', $image_dir);
 333  
 334      if ($image_dir && ($image_dir[0] == '/' || $image_dir[0] == '\\'))
 335      {
 336          $image_dir = '';
 337      }
 338      $file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file;
 339  
 340      if ((@file_exists($file_path) && @is_readable($file_path)) && !headers_sent())
 341      {
 342          header('Pragma: public');
 343  
 344          $image_data = @getimagesize($file_path);
 345          header('Content-Type: ' . image_type_to_mime_type($image_data[2]));
 346              
 347          if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7))
 348          {
 349              header('Content-Disposition: attachment; ' . header_filename($file));
 350  
 351              if (strpos(strtolower($browser), 'msie 6.0') !== false)
 352              {
 353                  header('Expires: -1');
 354              }
 355              else
 356              {
 357                  header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));
 358              }
 359          }
 360          else
 361          {
 362              header('Content-Disposition: inline; ' . header_filename($file));
 363              header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));
 364          }
 365  
 366          $size = @filesize($file_path);
 367          if ($size)
 368          {
 369              header("Content-Length: $size");
 370          }
 371  
 372          if (@readfile($file_path) == false)
 373          {
 374              $fp = @fopen($file_path, 'rb');
 375  
 376              if ($fp !== false)
 377              {
 378                  while (!feof($fp))
 379                  {
 380                      echo fread($fp, 8192);
 381                  }
 382                  fclose($fp);
 383              }
 384          }
 385  
 386          flush();
 387      }
 388      else
 389      {
 390          send_status_line(404, 'Not Found');
 391      }
 392  }
 393  
 394  /**
 395  * Wraps an url into a simple html page. Used to display attachments in IE.
 396  * this is a workaround for now; might be moved to template system later
 397  * direct any complaints to 1 Microsoft Way, Redmond
 398  */
 399  function wrap_img_in_html($src, $title)
 400  {
 401      echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">';
 402      echo '<html>';
 403      echo '<head>';
 404      echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
 405      echo '<title>' . $title . '</title>';
 406      echo '</head>';
 407      echo '<body>';
 408      echo '<div>';
 409      echo '<img src="' . $src . '" alt="' . $title . '" />';
 410      echo '</div>';
 411      echo '</body>';
 412      echo '</html>';
 413  }
 414  
 415  /**
 416  * Send file to browser
 417  */
 418  function send_file_to_browser($attachment, $upload_dir, $category)
 419  {
 420      global $user, $db, $config, $phpbb_root_path;
 421  
 422      $filename = $phpbb_root_path . $upload_dir . '/' . $attachment['physical_filename'];
 423  
 424      if (!@file_exists($filename))
 425      {
 426          send_status_line(404, 'Not Found');
 427          trigger_error('ERROR_NO_ATTACHMENT');
 428      }
 429  
 430      // Correct the mime type - we force application/octetstream for all files, except images
 431      // Please do not change this, it is a security precaution
 432      if ($category != ATTACHMENT_CATEGORY_IMAGE || strpos($attachment['mimetype'], 'image') !== 0)
 433      {
 434          $attachment['mimetype'] = (strpos(strtolower($user->browser), 'msie') !== false || strpos(strtolower($user->browser), 'opera') !== false) ? 'application/octetstream' : 'application/octet-stream';
 435      }
 436  
 437      if (@ob_get_length())
 438      {
 439          @ob_end_clean();
 440      }
 441  
 442      // Now send the File Contents to the Browser
 443      $size = @filesize($filename);
 444  
 445      // To correctly display further errors we need to make sure we are using the correct headers for both (unsetting content-length may not work)
 446  
 447      // Check if headers already sent or not able to get the file contents.
 448      if (headers_sent() || !@file_exists($filename) || !@is_readable($filename))
 449      {
 450          // PHP track_errors setting On?
 451          if (!empty($php_errormsg))
 452          {
 453              send_status_line(500, 'Internal Server Error');
 454              trigger_error($user->lang['UNABLE_TO_DELIVER_FILE'] . '<br />' . sprintf($user->lang['TRACKED_PHP_ERROR'], $php_errormsg));
 455          }
 456  
 457          send_status_line(500, 'Internal Server Error');
 458          trigger_error('UNABLE_TO_DELIVER_FILE');
 459      }
 460  
 461      // Now the tricky part... let's dance
 462      header('Pragma: public');
 463  
 464      /**
 465      * Commented out X-Sendfile support. To not expose the physical filename within the header if xsendfile is absent we need to look into methods of checking it's status.
 466      *
 467      * Try X-Sendfile since it is much more server friendly - only works if the path is *not* outside of the root path...
 468      * lighttpd has core support for it. An apache2 module is available at http://celebnamer.celebworld.ws/stuff/mod_xsendfile/
 469      *
 470      * Not really ideal, but should work fine...
 471      * <code>
 472      *    if (strpos($upload_dir, '/') !== 0 && strpos($upload_dir, '../') === false)
 473      *    {
 474      *        header('X-Sendfile: ' . $filename);
 475      *    }
 476      * </code>
 477      */
 478  
 479      // Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.
 480      header('Content-Type: ' . $attachment['mimetype']);
 481          
 482      if (phpbb_is_greater_ie_version($user->browser, 7))
 483      {
 484          header('X-Content-Type-Options: nosniff');
 485      }
 486  
 487      if ($category == ATTACHMENT_CATEGORY_FLASH && request_var('view', 0) === 1)
 488      {
 489          // We use content-disposition: inline for flash files and view=1 to let it correctly play with flash player 10 - any other disposition will fail to play inline
 490          header('Content-Disposition: inline');
 491      }
 492      else
 493      {
 494          if (empty($user->browser) || ((strpos(strtolower($user->browser), 'msie') !== false) && !phpbb_is_greater_ie_version($user->browser, 7)))
 495          {
 496              header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
 497              if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false))
 498              {
 499                  header('expires: -1');
 500              }
 501          }
 502          else
 503          {
 504              header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
 505              if (phpbb_is_greater_ie_version($user->browser, 7) && (strpos($attachment['mimetype'], 'image') !== 0))
 506              {
 507                  header('X-Download-Options: noopen');
 508              }
 509          }
 510      }
 511  
 512      if ($size)
 513      {
 514          header("Content-Length: $size");
 515      }
 516  
 517      // Close the db connection before sending the file
 518      $db->sql_close();
 519  
 520      if (!set_modified_headers($attachment['filetime'], $user->browser))
 521      {
 522          // Try to deliver in chunks
 523          @set_time_limit(0);
 524  
 525          $fp = @fopen($filename, 'rb');
 526  
 527          if ($fp !== false)
 528          {
 529              while (!feof($fp))
 530              {
 531                  echo fread($fp, 8192);
 532              }
 533              fclose($fp);
 534          }
 535          else
 536          {
 537              @readfile($filename);
 538          }
 539  
 540          flush();
 541      }
 542      file_gc();
 543  }
 544  
 545  /**
 546  * Get a browser friendly UTF-8 encoded filename
 547  */
 548  function header_filename($file)
 549  {
 550      $user_agent = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
 551  
 552      // There be dragons here.
 553      // Not many follows the RFC...
 554      if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Safari') !== false || strpos($user_agent, 'Konqueror') !== false)
 555      {
 556          return "filename=" . rawurlencode($file);
 557      }
 558  
 559      // follow the RFC for extended filename for the rest
 560      return "filename*=UTF-8''" . rawurlencode($file);
 561  }
 562  
 563  /**
 564  * Check if downloading item is allowed
 565  */
 566  function download_allowed()
 567  {
 568      global $config, $user, $db;
 569  
 570      if (!$config['secure_downloads'])
 571      {
 572          return true;
 573      }
 574  
 575      $url = (!empty($_SERVER['HTTP_REFERER'])) ? trim($_SERVER['HTTP_REFERER']) : trim(getenv('HTTP_REFERER'));
 576  
 577      if (!$url)
 578      {
 579          return ($config['secure_allow_empty_referer']) ? true : false;
 580      }
 581  
 582      // Split URL into domain and script part
 583      $url = @parse_url($url);
 584  
 585      if ($url === false)
 586      {
 587          return ($config['secure_allow_empty_referer']) ? true : false;
 588      }
 589  
 590      $hostname = $url['host'];
 591      unset($url);
 592  
 593      $allowed = ($config['secure_allow_deny']) ? false : true;
 594      $iplist = array();
 595  
 596      if (($ip_ary = @gethostbynamel($hostname)) !== false)
 597      {
 598          foreach ($ip_ary as $ip)
 599          {
 600              if ($ip)
 601              {
 602                  $iplist[] = $ip;
 603              }
 604          }
 605      }
 606  
 607      // Check for own server...
 608      $server_name = $user->host;
 609  
 610      // Forcing server vars is the only way to specify/override the protocol
 611      if ($config['force_server_vars'] || !$server_name)
 612      {
 613          $server_name = $config['server_name'];
 614      }
 615  
 616      if (preg_match('#^.*?' . preg_quote($server_name, '#') . '.*?$#i', $hostname))
 617      {
 618          $allowed = true;
 619      }
 620  
 621      // Get IP's and Hostnames
 622      if (!$allowed)
 623      {
 624          $sql = 'SELECT site_ip, site_hostname, ip_exclude
 625              FROM ' . SITELIST_TABLE;
 626          $result = $db->sql_query($sql);
 627  
 628          while ($row = $db->sql_fetchrow($result))
 629          {
 630              $site_ip = trim($row['site_ip']);
 631              $site_hostname = trim($row['site_hostname']);
 632  
 633              if ($site_ip)
 634              {
 635                  foreach ($iplist as $ip)
 636                  {
 637                      if (preg_match('#^' . str_replace('\*', '.*?', preg_quote($site_ip, '#')) . '$#i', $ip))
 638                      {
 639                          if ($row['ip_exclude'])
 640                          {
 641                              $allowed = ($config['secure_allow_deny']) ? false : true;
 642                              break 2;
 643                          }
 644                          else
 645                          {
 646                              $allowed = ($config['secure_allow_deny']) ? true : false;
 647                          }
 648                      }
 649                  }
 650              }
 651  
 652              if ($site_hostname)
 653              {
 654                  if (preg_match('#^' . str_replace('\*', '.*?', preg_quote($site_hostname, '#')) . '$#i', $hostname))
 655                  {
 656                      if ($row['ip_exclude'])
 657                      {
 658                          $allowed = ($config['secure_allow_deny']) ? false : true;
 659                          break;
 660                      }
 661                      else
 662                      {
 663                          $allowed = ($config['secure_allow_deny']) ? true : false;
 664                      }
 665                  }
 666              }
 667          }
 668          $db->sql_freeresult($result);
 669      }
 670  
 671      return $allowed;
 672  }
 673  
 674  /**
 675  * Check if the browser has the file already and set the appropriate headers-
 676  * @returns false if a resend is in order.
 677  */
 678  function set_modified_headers($stamp, $browser)
 679  {
 680      // let's see if we have to send the file at all
 681      $last_load     =  isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false;
 682          
 683      if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie_version($browser, 7))
 684      {
 685          if ($last_load !== false && $last_load >= $stamp)
 686          {
 687              send_status_line(304, 'Not Modified');
 688              // seems that we need those too ... browsers
 689              header('Pragma: public');
 690              header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));
 691              return true;
 692          }
 693          else
 694          {
 695              header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $stamp) . ' GMT');
 696          }
 697      }
 698      return false;
 699  }
 700  
 701  function file_gc()
 702  {
 703      global $cache, $db;
 704      if (!empty($cache))
 705      {
 706          $cache->unload();
 707      }
 708      $db->sql_close();
 709      exit;
 710  }
 711  
 712  /**
 713  * Check if the browser is internet explorer version 7+
 714  *
 715  * @param string $user_agent    User agent HTTP header
 716  * @param int $version IE version to check against
 717  *
 718  * @return bool true if internet explorer version is greater than $version
 719  */
 720  function phpbb_is_greater_ie_version($user_agent, $version)
 721  {
 722      if (preg_match('/msie (\d+)/', strtolower($user_agent), $matches))
 723      {
 724          $ie_version = (int) $matches[1];
 725          return ($ie_version > $version);
 726      }
 727      else
 728      {
 729          return false;
 730      }
 731  }
 732  
 733  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1