PHP Forums Archive

PHP Whois script - Help Needed

Tags: whois, IP address, linux

milneandfletch posted on 2010-01-27 09:01:18 #

Hi Guys,
I've looked at the script and i could do with a hand!
What i ideally want it to know who has accessed my site and who there isp is.
I have found that if i use a website with whois setup on the IP address information.
I can put the client ip address in and get the ISP info back.

What i am looking for is a script that can do that.
You script comes close but i don't know how to amend it for IP address or how to have it simply return the information to the screen.

Any ideas on where i need to start?
I've also noticed that there is no .co.uk setup, is that easy to do?

Thanks

Peter

Comments / discussions

Olaf posted on 2010-01-27 10:06:29 #

Hello Peter,

to get information about an IP address you don't need a Whois script like this one, try this code:

exec('whois 77.243.225.68', $str);
print_r($str);

Is this the information you're looking for?
Using this function you need 2 requirements:

  1. access to the Linux command line (from PHP)
  2. the Linux tool "whois" must be installed

milneandfletch posted on 2010-01-27 10:34:27 #

Hi,
Well the code sort of works, i get a long string of data with [1].... [2].... information.
What i was hoping was to use the $_SERVER['REMOTE_ADDR' command to get the visiting users ip and then run it through this.
Is there a better way of displaying the information?

Is it just in an array? If so how do i look at parts of an array? is it like c?

Thanks

Pete

Olaf posted on 2010-01-27 10:51:37 #

Hi,

yes using the variable $_SERVER['REMOTE_ADDR'] is how you do it.

Check first if the format for the result is always the same (it's possible that you need a different parser for different IP ranges).

Next you need to split the array into pieces, check the arrays section from the PHP Manual on php.net