Analisys For Luca »  Show posts from    to     

Icy Phoenix


Old Support Topics - Analisys For Luca



fucile [ Sat 24 Oct, 2009 08:13 ]
Post subject: Analisys For Luca
Thanks in advance

I'm creating a user info block and I'm putting the functions computed by $ _SERVER

Code: [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


Informpro [ Sat 24 Oct, 2009 09:15 ]
Post subject: Re: Analisys For Luca
use this function instead (for get IP address):
Code: [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: [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. }


fucile [ Sat 24 Oct, 2009 17:32 ]
Post 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]


Mighty Gorgon [ Mon 26 Oct, 2009 15:48 ]
Post subject: Re: Analisys For Luca
You need to use the explode function to be able to match only the first triplet.

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


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


fucile [ Mon 26 Oct, 2009 21:53 ]
Post subject: Re: Analisys For Luca
Thanks Luca

I knew that I'd been of assistance

Hello Fucile


fucile [ Mon 02 Nov, 2009 06:38 ]
Post 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 ]




Powered by Icy Phoenix