Vous êtes ici Codes PHP et MySQL > Sécurité > Fonction de récupuration d'ip

 

Fonction de récupuration d'ip

Cette fonction de récupération d'ip est plus efficace que bien des fonctions que l'on peut trouver. Elle est tirée du fameux script PhpMyAdmin...
 
R@f
[17] sources en PHP voir
Code vu 6659 fois
Enregistré le 08 Sept 2007
  • Digg ce code sur digg.com
  • Bookmark ce code sur del.icio.us
  • Bookmark ce code sur Google
  • Bookmark ce code sur Yahoo
  • Ajoute Fonction de récupuration d'ip
  • Partage ce code sur Facebook
 
 
 
 

Code Source


01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
 
<?php
/******************************************************************************/
/*                                                                            */
/*                       __        ____                                       */
/*                 ___  / /  ___  / __/__  __ _____________ ___               */
/*                / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-<               */
/*               / .__/_//_/ .__/___/\___/\_,_/_/  \__/\__/___/               */
/*              /_/       /_/                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
/*                                                                            */
/* Titre          : Fonction de récupuration d'ip                             */
/*                                                                            */
/* URL            : http://www.phpsources.org/scripts301-PHP.htm              */
/* Auteur         : R@f                                                       */
/* Date édition   : 08 Sept 2007                                              */
/*                                                                            */
/******************************************************************************/

function PMA_getIp(  )
{
    global $REMOTE_ADDR;
    global $HTTP_X_FORWARDED_FOR$HTTP_X_FORWARDED$HTTP_FORWARDED_FOR$HTTP_FORWARDED;
    global $HTTP_VIA$HTTP_X_COMING_FROM$HTTP_COMING_FROM;
    
    // Get some server/environment variables values
    if( empty( $REMOTE_ADDR ) && PMA_getenv'REMOTE_ADDR' ) )
        $REMOTE_ADDR PMA_getenv(  'REMOTE_ADDR'  );
    if ( empty( $HTTP_X_FORWARDED_FOR ) && PMA_getenv'HTTP_X_FORWARDED_FOR' ) 
)
        $HTTP_X_FORWARDED_FOR PMA_getenv'HTTP_X_FORWARDED_FOR' );
    if( empty( $HTTP_X_FORWARDED ) && PMA_getenv'HTTP_X_FORWARDED' ) )
        $HTTP_X_FORWARDED PMA_getenv'HTTP_X_FORWARDED' );
    if ( empty( $HTTP_FORWARDED_FOR ) && PMA_getenv'HTTP_FORWARDED_FOR' ) )
        $HTTP_FORWARDED_FOR PMA_getenv'HTTP_FORWARDED_FOR' );
    if ( empty( $HTTP_FORWARDED ) && PMA_getenv'HTTP_FORWARDED' ) )
        $HTTP_FORWARDED PMA_getenv'HTTP_FORWARDED' );
    if ( empty( $HTTP_VIA ) && PMA_getenv'HTTP_VIA' ) )
        $HTTP_VIA PMA_getenv'HTTP_VIA' );
    if ( empty( $HTTP_X_COMING_FROM ) && PMA_getenv'HTTP_X_COMING_FROM' ) )
        $HTTP_X_COMING_FROM PMA_getenv'HTTP_X_COMING_FROM' );
    if ( empty( $HTTP_COMING_FROM ) && PMA_getenv'HTTP_COMING_FROM' ) )
        $HTTP_COMING_FROM PMA_getenv'HTTP_COMING_FROM' );

    // Gets the default ip sent by the user
    if ( !empty( $REMOTE_ADDR ) )
        $direct_ip $REMOTE_ADDR;
        
    // Gets the proxy ip sent by the user
    $proxy_ip '';
    if ( !empty( $HTTP_X_FORWARDED_FOR ) )
        $proxy_ip $HTTP_X_FORWARDED_FOR;
    elseif ( !empty( $HTTP_X_FORWARDED ) )
        $proxy_ip $HTTP_X_FORWARDED;
    elseif ( !empty( $HTTP_FORWARDED_FOR ) )
        $proxy_ip $HTTP_FORWARDED_FOR;
    elseif ( !empty( $HTTP_FORWARDED ) )
        $proxy_ip $HTTP_FORWARDED;
    elseif ( !empty( $HTTP_VIA ) )
        $proxy_ip $HTTP_VIA;
    elseif ( !empty( $HTTP_X_COMING_FROM ) )
        $proxy_ip $HTTP_X_COMING_FROM;
    elseif ( !empty( $HTTP_COMING_FROM ) )
        $proxy_ip $HTTP_COMING_FROM;
    // end if... elseif...

    // Returns the true IP if it has been found, else FALSE
    if ( empty( $proxy_ip ) )
        return $direct_ip// True IP without proxy
    else
    {
        $is_ip preg_match'|^( [0-9]{1,3}\. ){3,3}[0-9]{1,3}|'$proxy_ip$regs );
        if ( $is_ip && ( count$regs ) >  ) )
            return $regs[]; // True IP behind a proxy
        else
        {
            // Can't define IP: there is a proxy but we don't have
            // information about the true IP
            return FALSE;
        }
    } // end if... else...
// end of the 'PMA_getIp(  )' function

/**
* trys to find the value for the given environment vriable name
*
* searchs in $_SERVER, $_ENV than trys getenv(  ) and apache_getenv(  )
* in this order
*
* @param string $var_name variable name
* @return string value of $var or empty string
*/
function PMA_getenv$var_name ) 
{
    if ( isset( $_SERVER[$var_name] ) )
        return $_SERVER[$var_name];
    elseif ( isset( $_ENV[$var_name] ) )
        return $_ENV[$var_name];
    elseif ( getenv$var_name ) )
        return getenv$var_name );
    elseif ( function_exists'apache_getenv' ) && apache_getenv$var_nametrue ) )
        return apache_getenv$var_nametrue );
    
    return '';
}
?>


 

Fonctions du code

: Détermine si une variable contient une valeur non nulle - (PHP 4, PHP 5)
: Expression rationnelle standard - (PHP 4, PHP 5)
: Compte le nombre d'éléments d'un tableau ou le nombre de propriétés...
: Détermine si une variable est affectée - (PHP 4, PHP 5)
: Retourne la valeur d'une variable d'environnement - (PHP 4, PHP 5)
: Lit une variable de processus Apache - (PHP 4 >= 4.3.0, PHP 5)
: Indique si une fonction est définie - (PHP 4, PHP 5)
Commentaire
 Des explications possibles?

Parce que là, j'y pige pas grand-chose ...
 
Ajouter un commentaire
Code de sécurité

Attention: Les champs marqués d'une étoile * sont obligatoires
 
Librairie PHP

Connexion

 
 

Sécurité

 
 

PHP

 
 
 
PHP 5 ; MySQL 4 Livre PHP

PHP 5 ; MySQL 4
 
    Offres d'emploi

Plus de 500 offres d'emploi PHP/MySQL

Offres d'emploi
 
    Editeur PHP
 
        Publicité