Вход Регистрация
Файл: include/common_func.php
Строк: 121
<?php

function getHttpVar($name)
{
    if(isset(
$_POST[$name]))
    {
        return 
trim(strip_tags($_POST[$name]));
    }
    return 
"";
        
}

function 
getSessionVar($name)
{
    if(isset(
$_SESSION[$name]))
    {
        return 
$_SESSION[$name];
    }
    return 
"";
        
}

function 
getCountRecord($db,$field,$table,$cond1)
{
    
$sql "select $field from $table where $field='$cond1'";

    
$result $db->query($sql);
    
    if (
DB::isError($result)) {
            die(
$result->toString());
    }
    
    
$count $result->numRows();

    return 
$count;    
}

function 
checkPlayerSession()
{
    if(isset(
$_SESSION['vnum']) && isset($_SESSION['pass'])){
        return;
    }
    
      
header("Location: index.php");
    exit();
}

/**
    move player on need page select status
*/
function checkPlayerState($player)
{
  
//get session expired
  
$online $player->getOnline();
  
  if(
$online==0){
     
header("Location: index.php");
     exit();
  }
    
//get state
    
$state $player->getState();
    if(
$state==STATE_COMBAT){
        
header("Location: battle_mobs.php");
         exit();
    }
    if(
$state!=STATE_STAND){
     
header("Location: state.php");
     exit();
    }    
}

function 
getUniqValue()
{
    
//return 32 byte value
    // no prefix
    
$token md5(uniqid(""));

    
// better, difficult to guess
    
$better_token md5(uniqid(rand(), true));
    
    return 
$better_token;
}

function 
getUniqID()
{
    
$id mt_rand();
    
    return 
$id;
}

function 
getTimes($timestamp)
{
    return 
date('H:i',$timestamp);
}

function 
getDates($timestamp)
{
    return 
date('d:m',$timestamp);
}

function 
getDatesYear($timestamp)
{
    return 
date('d.m.Y',$timestamp);
}

function 
getDatesYearTime ($timestamp)
{
    return 
date('H:i d.m.Y',$timestamp);
}

function 
getChatTime ($timestamp)
{
    return 
date('d.m H:i',$timestamp);
}



//type != 0 get average
function phpmud_get_d_value($str,$type=0)
{
 
//check on int
 
if(is_int($str)) return $str;
    
 
//str in format xdy+z
 // x count round(1,y)+z(bonus)
 
$arr explode('d',$str);
 
$x=$arr[0];
 
$pos strpos($str,'+');
 if(
$pos==false){
     
$y=$arr[1];
    
$z=0;
 }else{
       
$arr1=explode('+',$arr[1]);
    
$y=(int)$arr1[0];
    
$z=(int)$arr1[1];
 }
 
$sum=$z;
 if(
$type==0){
    for(
$i=0;$i<$x;$i++){
        
$sum=$sum+mt_rand(1,$y);
    }
 }else{
    for(
$i=0;$i<$x;$i++){
        
$sum=$sum+$y/2;
    } 
 }
 return 
floor($sum);
}

/**
    Get text info about state
*/
function getStateText($state)
{
    
$txt="";
    
    switch (
$state)
    {
        case 
STATE_STAND:
            
$txt="уФПЙФ";
            break;
        case 
STATE_WORK:
            
$txt="тБВПФБЕФ";
            break;
        case 
STATE_DEAD:
            
$txt="нЕТФЧ";
            break;
        case 
STATE_COMBAT:
            
$txt="уТБЦБЕФУС";
            break;
    }
    
    return 
$txt;
}

function 
checkFile($filename)
{
    return 
file_exists($filename);
}

function 
generatePasswd($len){
    
$passwd="";
    for(
$i=0;$i<$len;$i++){
        
$passwd.=chr(rand(65,89));
    }
    
    return 
$passwd;
}

function 
getUserIP()
{
    if      ( 
getenv("HTTP_CLIENT_IP") )       $ip getenv("HTTP_CLIENT_IP");
    else if ( 
getenv("HTTP_X_FORWARDED_FOR") ) $ip getenv("HTTP_X_FORWARDED_FOR");
    else if ( 
getenv("HTTP_FORWARDED_FOR") )   $ip getenv("HTTP_FORWARDED_FOR");
    else if ( 
getenv("REMOTE_ADDR") )          $ip getenv("REMOTE_ADDR");
    else 
$ip "UNKNOWN";
    return 
$ip;

}

?>
Онлайн: 1
Реклама