<?php

function login($login){
    if (preg_match("/^[a-zA-Zа-яА-Я0-9\-_]+$/", $login)){
      $login = str_replace("'"," ",$login);
      $login = htmlentities($login, ENT_QUOTES, 'WINDOWS-1251');
      return $login;

    }else{
      echo "<fieldset class=warning>Введенные данные содержат запрещенные символы. Проверьте правильность ввода";include('footer.php');exit();

    }

}

function text($text){
		$text = str_replace(";"," ",$text);
		$text = str_replace("$"," ",$text);
		$text = str_replace("'"," ",$text);
		$text = str_replace("<"," ",$text);
		$text = str_replace(">"," ",$text);
		$text = strip_tags($text);
		$text = htmlspecialchars($text, ENT_QUOTES,'WINDOWS-1251');
		return $text;

}

function myHashData ($data){
		$md5 = substr(md5($data.'anti-hack'), 0, 30);
		return $md5;

}

function getRealIP()
{

   if( $_SERVER['HTTP_X_FORWARDED_FOR'] != '' )
   {
      $client_ip =
         ( !empty($_SERVER['REMOTE_ADDR']) ) ?
            $_SERVER['REMOTE_ADDR']
            :
            ( ( !empty($_ENV['REMOTE_ADDR']) ) ?
               $_ENV['REMOTE_ADDR']
               :
               "unknown" );
      $entries = preg_split('[, ]', $_SERVER['HTTP_X_FORWARDED_FOR']);

      reset($entries);
      while (list(, $entry) = each($entries))
      {
         $entry = trim($entry);
         if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $entry, $ip_list) )
         {
            // http://www.faqs.org/rfcs/rfc1918.html
            $private_ip = array(
                  '/^0\./',
                  '/^127\.0\.0\.1/',
                  '/^192\.168\..*/',
                  '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/',
                  '/^10\..*/');

            $found_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);

            if ($client_ip != $found_ip)
            {
               $client_ip = $found_ip;
               break;
            }
         }
      }
   }
   else
   {
      $client_ip =
         ( !empty($_SERVER['REMOTE_ADDR']) ) ?
            $_SERVER['REMOTE_ADDR']
            :
            ( ( !empty($_ENV['REMOTE_ADDR']) ) ?
               $_ENV['REMOTE_ADDR']
               :
               "unknown" );
   }

   return $client_ip;

}

?>