Changeset 359


Ignore:
Timestamp:
Feb 11, 2004, 11:31:08 PM (20 years ago)
Author:
z0rglub
Message:

only refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/common.inc.php

    r354 r359  
    11<?php
    22// +-----------------------------------------------------------------------+
    3 // |                           common.inc.php                                |
     3// |                           common.inc.php                              |
    44// +-----------------------------------------------------------------------+
    55// | application   : PhpWebGallery <http://phpwebgallery.net>              |
     
    2525// | USA.                                                                  |
    2626// +-----------------------------------------------------------------------+
    27 // determine the initial instant to indicate the generation time of this page
     27
     28// determine the initial instant to indicate the generation time of this
     29// page
    2830$t1 = explode( ' ', microtime() );
    2931$t2 = explode( '.', $t1[0] );
     
    3335
    3436//
    35 // addslashes to vars if magic_quotes_gpc is off
    36 // this is a security precaution to prevent someone
    37 // trying to break out of a SQL statement.
     37// addslashes to vars if magic_quotes_gpc is off this is a security
     38// precaution to prevent someone trying to break out of a SQL statement.
    3839//
    3940if( !get_magic_quotes_gpc() )
    4041{
    41   if( is_array($HTTP_GET_VARS) )
    42   {
    43     while( list($k, $v) = each($HTTP_GET_VARS) )
     42  if( is_array( $_GET ) )
     43  {
     44    while( list($k, $v) = each($_GET) )
    4445    {
    45           if( is_array($HTTP_GET_VARS[$k]) )
    46           {
    47         while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
     46      if( is_array($_GET[$k]) )
     47      {
     48        while( list($k2, $v2) = each($_GET[$k]) )
    4849        {
    49                   $HTTP_GET_VARS[$k][$k2] = addslashes($v2);
    50                 }
    51           @reset($HTTP_GET_VARS[$k]);
    52           }
    53           else
    54           {
    55                 $HTTP_GET_VARS[$k] = addslashes($v);
    56           }
    57         }
    58         @reset($HTTP_GET_VARS);
     50          $_GET[$k][$k2] = addslashes($v2);
     51        }
     52        @reset($_GET[$k]);
     53      }
     54      else
     55      {
     56        $_GET[$k] = addslashes($v);
     57      }
     58    }
     59    @reset($_GET);
    5960  }
    6061 
    61   if( is_array($HTTP_POST_VARS) )
    62   {
    63         while( list($k, $v) = each($HTTP_POST_VARS) )
    64         {
    65           if( is_array($HTTP_POST_VARS[$k]) )
    66           {
    67                 while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
    68                 {
    69                   $HTTP_POST_VARS[$k][$k2] = addslashes($v2);
    70                 }
    71           @reset($HTTP_POST_VARS[$k]);
    72           }
    73           else
    74           {
    75                 $HTTP_POST_VARS[$k] = addslashes($v);
    76           }
     62  if( is_array($_POST) )
     63  {
     64    while( list($k, $v) = each($_POST) )
     65    {
     66      if( is_array($_POST[$k]) )
     67      {
     68        while( list($k2, $v2) = each($_POST[$k]) )
     69        {
     70          $_POST[$k][$k2] = addslashes($v2);
     71        }
     72        @reset($_POST[$k]);
     73      }
     74      else
     75      {
     76        $_POST[$k] = addslashes($v);
     77      }
    7778    }
    78     @reset($HTTP_POST_VARS);
    79   }
    80 
    81   if( is_array($HTTP_COOKIE_VARS) )
    82   {
    83     while( list($k, $v) = each($HTTP_COOKIE_VARS) )
     79    @reset($_POST);
     80  }
     81
     82  if( is_array($_COOKIE) )
     83  {
     84    while( list($k, $v) = each($_COOKIE) )
    8485    {
    85           if( is_array($HTTP_COOKIE_VARS[$k]) )
    86           {
    87             while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
    88             {
    89                   $HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
    90             }
    91             @reset($HTTP_COOKIE_VARS[$k]);
    92           }
    93           else
    94           {
    95             $HTTP_COOKIE_VARS[$k] = addslashes($v);
    96           }
     86      if( is_array($_COOKIE[$k]) )
     87      {
     88        while( list($k2, $v2) = each($_COOKIE[$k]) )
     89        {
     90          $_COOKIE[$k][$k2] = addslashes($v2);
     91        }
     92        @reset($_COOKIE[$k]);
     93      }
     94      else
     95      {
     96        $_COOKIE[$k] = addslashes($v);
     97      }
    9798    }
    98     @reset($HTTP_COOKIE_VARS);
    99   }
    100 }
    101 
    102 //
    103 // Define some basic configuration arrays this also prevents
    104 // malicious rewriting of language and otherarray values via
    105 // URI params
     99    @reset($_COOKIE);
     100  }
     101}
     102
     103//
     104// Define some basic configuration arrays this also prevents malicious
     105// rewriting of language and otherarray values via URI params
    106106//
    107107$conf = array();
     
    110110$lang = array();
    111111
    112 include($phpwg_root_path .'config.php');
    113 
    114112if( !defined("PHPWG_INSTALLED") )
    115113{
    116         header("Location: install.php");
    117         exit;
    118 }
    119 
    120 include($phpwg_root_path . 'include/constants.php');
    121 include($phpwg_root_path . 'include/functions.inc.php');
    122 include($phpwg_root_path . 'include/template.php');
    123 include($phpwg_root_path . 'include/vtemplate.class.php');
    124 include($phpwg_root_path . 'include/config.inc.php');
     114  header( 'Location: install.php' );
     115  exit;
     116}
     117
     118include( $phpwg_root_path.'include/constants.php' );
     119include( $phpwg_root_path.'include/functions.inc.php' );
     120include( $phpwg_root_path.'include/template.php' );
     121include( $phpwg_root_path.'include/vtemplate.class.php' );
     122include( $phpwg_root_path.'include/config.inc.php' );
    125123
    126124//
     
    129127
    130128mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
    131     or die ( "Could not connect to server" );
     129or die ( "Could not connect to server" );
    132130mysql_select_db( $cfgBase )
    133     or die ( "Could not connect to database" );
     131or die ( "Could not connect to database" );
    134132       
    135133//
    136134// Obtain and encode users IP
    137135//
    138 if( getenv('HTTP_X_FORWARDED_FOR') != '' )
    139 {
    140   $client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );
    141 
    142   if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip_list) )
    143   {
    144     $private_ip = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.16\..*/', '/^10.\.*/', '/^224.\.*/', '/^240.\.*/');
     136if ( getenv( 'HTTP_X_FORWARDED_FOR' ) != '' )
     137{
     138  $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
     139
     140  if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/",
     141                  getenv('HTTP_X_FORWARDED_FOR'), $ip_list) )
     142  {
     143    $private_ip = array( '/^0\./'
     144                         ,'/^127\.0\.0\.1/'
     145                         ,'/^192\.168\..*/'
     146                         ,'/^172\.16\..*/'
     147                         ,'/^10.\.*/'
     148                         ,'/^224.\.*/'
     149                         ,'/^240.\.*/'
     150      );
    145151    $client_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
    146152  }
     
    148154else
    149155{
    150   $client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : $REMOTE_ADDR );
     156  $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
    151157}
    152158$user_ip = encode_ip($client_ip);
    153159
    154160//
    155 // Setup forum wide options, if this fails
    156 // then we output a CRITICAL_ERROR since
    157 // basic forum information is not available
    158 //
    159 $sql = "SELECT * FROM " . CONFIG_TABLE;
     161// Setup forum wide options, if this fails then we output a CRITICAL_ERROR
     162// since basic forum information is not available
     163//
     164$sql = 'SELECT * FROM '.CONFIG_TABLE;
    160165if( !($result = mysql_query($sql)) )
    161166{
     
    189194}
    190195
    191 if (file_exists('install.php') && !DEBUG)
    192 {
    193         die('Please ensure both the install/ and contrib/ directories are deleted');
    194 }
    195 
    196 
    197196//---------------
    198197// A partir d'ici il faudra dispatcher le code dans d'autres fichiers
Note: See TracChangeset for help on using the changeset viewer.