Analisys For Luca


Subject: 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

Profile PM  
Subject: 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. }

Profile PM  
Subject: 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]

Profile PM  
Subject: 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';
}

Subject: Re: Analisys For Luca
Thanks Luca

I knew that I'd been of assistance

Hello Fucile

Profile PM  
Subject: 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 ]

Profile PM  

Page 1 of 1


  
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

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Generation Time: 0.3631s (PHP: 10% SQL: 90%)
SQL queries: 15 - Debug Off - GZIP Enabled