Icy Phoenix

     
 


Post new topic  Reply to topic 
Page 1 of 1
 
 
Reply with quote Download Post 
Post Analisys For Luca 
 
Thanks in advance

I'm creating a user info block and I'm putting the functions computed by $ _SERVER
 
Code: [Download] [Hide] [Select]

function GetIp()
{
    $ip = array(
        '127.0.0.1'  => 'Local Host',
        '151'  => 'Libero Infostrada',
        '87'  => 'Telecom Italia',
        '93'  => 'Tele2 Adsl',
    );

    foreach($ip as $ip_string => $get_ip_string)
    {
        if(strpos($_SERVER['REMOTE_ADDR'], $ip_string ))
        {
            return $get_ip_string;
        }
    }

    return 'Sconosciuto';
}




On my Machine when call explorer or other browser returned " Sconosciuto " instead " Local Host ".

Can you help me understand?

Hi Fabrizio
 



 
fucileSend private message  
Back to topPage bottom
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us
 
Reply with quote Download Post 
Post Re: Analisys For Luca 
 
use this function instead (for get IP address):
Code: [Download] [Hide]
  1. function get_ip()  
  2.      {  
  3.          if($_SERVER)  
  4.              {  
  5.                  if($_SERVER['HTTP_X_FORWARDED_FOR'])  
  6.                      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
  7.                  elseif($_SERVER['HTTP_CLIENT_IP'])  
  8.                      $ip = $_SERVER['HTTP_CLIENT_IP'];  
  9.                  else  
  10.                      $ip = $_SERVER['REMOTE_ADDR'];  
  11.              }  
  12.        else  
  13.          {  
  14.              if(getenv('HTTP_X_FORWARDED_FOR'))  
  15.                  $ip = getenv('HTTP_X_FORWARDED_FOR');  
  16.              elseif(getenv('HTTP_CLIENT_IP'))  
  17.                  $ip = getenv('HTTP_CLIENT_IP');  
  18.              else  
  19.                  $ip = getenv('REMOTE_ADDR');  
  20.          }  
  21.  
  22.          return $ip;  
  23.      }  

and for the foreach, use this instead:
Code: [Download] [Hide]
  1. $ip_user = get_ip();  
  2. $key_ip_user = explode('.', $ip_user);  
  3. foreach($ip as $ip_string => $get_ip_string)  
  4.      {  
  5.          if(in_array($ip_string, $key_ip_user))  
  6.          {  
  7.              return $get_ip_string;  
  8.              break;  
  9.          }  
  10.      }  

 



 
InformproSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Analisys For Luca 
 
I want this script that works in this way

An array take the first three digits of IP and try to associate the name
Example
151.XXX => Libero Infostrada        echo in tpl: Libero Infostrada

If I wanted just the ip only associate the variable

$ _SERVER [REMOTE_ADDR]
 



 
fucileSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Analisys For Luca 
 
You need to use the explode function to be able to match only the first triplet.

Code: [Download] [Hide] [Select]
$ip_parts = explode('.', $ip_address);


In this way you can match any part of the IP with a condition like this:
Code: [Download] [Hide] [Select]
if ($ip_parts[0] == '151')
{
    $provider = 'Libero';
}

 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Analisys For Luca 
 
Thanks Luca

I knew that I'd been of assistance

Hello Fucile
 



 
fucileSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: Analisys For Luca 
 
This is the last script for the info_block User

Who is error ?

blocks_imp_info.php


Spoiler: [ Show ]


info_block.tpl

Spoiler: [ Show ]

 



 
fucileSend private message  
Back to topPage bottom
Post new topic  Reply to topic  Page 1 of 1
 


Display posts from previous:    

HideWas this topic useful?

Link this topic
URL
BBCode
HTML




 
Permissions List
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events