download this file: func.client.php view text/plain: func.client.php file encoding: EUC-KR [goback]
<?php
##
## this file name is 'func.client.php'
##
## client functions
##
## [author]
##  - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
##  - 2014.10.20 : add chrome
##  - 2014.08.07 : not support PHP/4, 'global' directive deleted
##  - 2003.03.07 : new build
##
## [references]
##
## [usage]
##
## [example]
##

## get client IP/hostname
##
## http://www.php.net/manual/en/language.variables.predefined.php
## http://www.rapidcontent.com/holly/mysql.phtml (example)
## http://theproxyconnection.com/report.html
## http://www.innotts.co.uk/help/publishing/ssi.shtml
## http://netmatrix0.virtualave.net/CrackersFAQ.txt.txt
##
## HTTP_CLIENT_IP :
##   - client :
##   - http via -> HTTP/1.1 Cluster_icache[C0A8010E] (Traffic-Server/4.0.18 [uScM]), 1.0
## HTTP_X_COMING_FROM :
##   - proxy server (or client ?)
##   - http via -> HTTP/1.1 Cluster_Scache[C0A80131] (Traffic-Server/4.0.18 [uScM])
## HTTP_COMING_FROM :
##   - proxy server (or client ?)
##   - http via -> HTTP/1.0 ?
## HTTP_X_FORWARDED_FOR :
##   - proxy server or client
##   - http via -> HTTP/1.1 1.0 jcsmr.anu.edu.au:xxxx (Squid/2.2.STABLE5), 1.0 cache2:80 (Squid/2.4.STABLE2)
##   - http via -> HTTP/1.1 Cluster_icache[C0A8010E] (Traffic-Server/4.0.18 [uScM]), 1.0
## HTTP_X_FORWARDED :
##   - proxy server or client
##   - http via -> 1.0 ? <squid host:port> (Squid/1.1.20)
## HTTP_FORWARDED_FOR, HTTP_FORWARDED :
##   - proxy server or client
##   - HTTP/1.0
## REMOTE_ADDR :
##   - proxy server or client:
## HTTP_PROXY, HTTP_SP_HOST :
##   - etc proxy server or client
##
function get_hostname($reverse=0$host='')
{
  if(!
$host)
  {
    
## $_SERVER['HTTP_VIA'] is some bug, so this delete, 2003.12.17
    ##
    
$tmp = array('HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR',
    
'HTTP_X_COMING_FROM','HTTP_X_FORWARDED','HTTP_FORWARDED_FOR',
    
'HTTP_FORWARDED','HTTP_COMING_FROM','HTTP_PROXY','HTTP_SP_HOST');

    foreach(
$tmp AS $v)
    { if(
$_SERVER[$v] != $_SERVER['REMOTE_ADDR']) break; }

    if(
$_SERVER[$v])
    { 
$host preg_replace(array('/unknown,/i','/,.*/'),'',$_SERVER[$v]); }

    
$host = ($host trim($host)) ? $host $_SERVER['REMOTE_ADDR'];
  }
  
$check $reverse ? @gethostbyaddr($host) : '';

  return 
$check $check $host;
}

## Á¢¼ÓÇÑ »ç¶÷ÀÌ »ç¿ëÇϴ ºê¶ó¿ìÁ®¸¦ ¾Ë±â À§ÇØ »ç¿ëµÇ´Â ÇÔ¼ö, ÇöÀç´Â FORM
## ÀÔ·ÂâÀÇ Å©±â°¡ ºê¶ó¿ìÁ®¸¶´Ù Æ²¸®°Ô ¼³Á¤µÇ´Â °ÍÀ» º¸Á¤Çϱâ À§ÇØ »ç¿ëµÊ
##
## SOURCE : JS-board
##
## patch : san2(at)linuxchannel.net, 2003.07.28
##
## return :
##    $agent    array(assoc)
##    $agent['br'] ºê¶ó¿ìÁ® Á¾·ù
##    $agent['os'] ¿î¿µÃ¼Á¦
##    $agent['ln'] ¾ð¾î (³Ý½ºÄÉÀÌÇÁ)
##    $agent['vr'] ºê¶ó¿ìÁ® ¹öÁ¯
##    $agent['co'] ¿¹¿Ü Á¤º¸
##
function get_agent()
{
  
$agent_env $_SERVER['HTTP_USER_AGENT'];

  
## get OS
  ##
  
if(preg_match('/NT/'$agent_env)) $agent['os'] = 'NT';
  else if(
preg_match('/Win/'$agent_env)) $agent['os'] = 'WIN';
  else if(
preg_match('/Linux/'$agent_env)) $agent['os'] = 'LINUX';
  else if(
preg_match('/FreeBSD/'$agent_env)) $agent['os'] = 'FreeBSD';
  else if(
preg_match('/Mac/'$agent_env)) $agent['os'] = 'MacOS';
  else 
$agent['os'] = 'OTHER';

  if(
preg_match('/MSIE/'$agent_env))
  {
    
$agent['br'] = 'MSIE';
    
$agent['vr'] = trim(preg_replace('/Mo.+MSIE ([^;]+);.+/i','\\1',$agent_env));
    
$agent['vr'] = preg_replace('/[a-z]/i','',$agent['vr']);
  }
  else if(
preg_match('/Chrome/i',$agent_env))
  {
    
$agent['br'] = 'CHROME';
  }
  else if(
preg_match('/Gecko|Galeon/i',$agent_env) && !preg_match('/Netscape/i',$agent_env))
  {
    
$agent['br'] = 'MOZL';

    
## language pack
    ##
    
if(preg_match('/en-US/i',$agent_env)) $agent['ln'] = 'EN';
    else if(
preg_match('/ko-KR/i',$agent_env)) $agent['ln'] = 'KO';
    else 
$agent['ln'] = 'OTHER';

    
## version 
    ##
    
if(preg_match('/rv:/',$agent_env))
    { 
$agent['vr'] = preg_replace('/^.+rv:([^)]+).*$/','\\1',$agent_env); }

    
## code-name
    ##
    
$agent['co'] = 'mozilla';
  }
  else if(
preg_match('/Konqueror/',$agent_env))
  {
    
$agent['br'] = 'KONQ';
    
$agent['vr'] = preg_replace('/^.+Konqueror\/([0-9]+).+$/','\\1',$agent_env);
  }
  else if(
preg_match('/Lynx/'$agent_env))
  {
    
$agent['br'] = 'LYNX';
  }
  else if(
preg_match('/w3m/i'$agent_env))
  {
    
$agent['br'] = 'W3M';
  }
  else if(
preg_match('/links/i'$agent_env))
  {
    
$agent['br'] = 'LINKS';
  }
  else if(
preg_match('/^Opera/'$agent_env))
  {
    
$agent['br'] = 'OPERA';
    
$agent['vr'] = preg_replace('/^Opera\/([0-9]+).+$/','\\1',$agent_env);
  }
  else if(
preg_match('/^Mozilla/'$agent_env)) // it's a Netscape
  
{
    
$agent['br'] = 'NS';

    
## code-name
    ##
    
$agent['co'] = 'mozilla';

    if(
preg_match('/\[en\]|en-US/i',$agent_env)) $agent['ln'] = 'EN';
    else if(
preg_match('/\[ko\]|ko-KR/i',$agent_env)) $agent['ln'] = 'KO';
    else 
$agent['ln'] = 'OTHER';

    
## version
    ##
    
if(preg_match('/Netscape/',$agent_env))
    { 
$agent['vr'] = preg_replace('/^.+Netscape[0-9]*\/([0-9]+).*$/','\\1',$agent_env); }
    else
    { 
$agent['vr'] = '4'; }

  }
  else 
$agent['br'] = 'OTHER';

  return 
$agent;
}

## check email address
## source : jsboard
##
function check_email($email$hchk=0)
{
  
$url trim($email);

  if(
$hchk)
  {
    
$host explode('@',$url);
    if(
preg_match('/^[\xA1-\xFEa-z0-9_-]+@[\xA1-\xFEa-z0-9_-]+\.[a-z0-9._-]+$/i',$url))
    {
        if(
checkdnsrr($host[1],"MX") || gethostbynamel($host[1]))
        { 
$check $url; }
    }
  } else
  {
    if(
preg_match('/^[\xA1-\xFEa-z0-9_-]+@[\xA1-\xFEa-z0-9_-]+\.[a-z0-9._-]+$/i',$url))
    { 
$check $url; }
  }

  return 
$check;
}

## URLÀÌ Á¤È®ÇÑ °ÍÀÎÁö °Ë»çÇϴ ÇÔ¼ö
##
function check_url($url)
{
  
$url trim($url);
 
  
## ÇÁ·ÎÅäÄÝ(http://, ftp://...)À» ³ªÅ¸³»´Â ºÎºÐÀÌ ¾øÀ» ¶§ ±âº»°ªÀ¸·Î
  ## http://¸¦ ºÙÀÓ
  ##
  
if(!preg_match('/^(http|https|ftp|telnet|news):\/\//i'$url))
  { 
$url 'http://'.$url; }

  if(!
preg_match('/(http|https|ftp|telnet|news):\/\/[\xA1-\xFEa-z0-9-]+'.
    
'\.[\xA1-\xFEa-zA-Z0-9,:&#@=_~%?\/.+-]+$/i',$url))
  { return; }

  return 
$url;
}

function 
get_mailhost($email)
{
  
$mxhost = array();
  
$weight = array();

  list(,
$host) = explode('@',$email);

  if(
checkdnsrr($host,'MX') && getmxrr($host,$mxhost,$weight))
  {
    
//@asort($weight);
    //@reset($weight);
    //list($idx) = each($weight); // get first one key
    //$host = $mxhost[$idx];
    
$host $mxhost[0]; // first host
  
}

  return 
$host;
}

?>