Determine ISP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Determine ISP?

Post by virgil »

Hi Php's, :)

Anyone know a way to return the $_SERVER['HTTP_USER_AGENT'] info
as an array?


$_SERVER['HTTP_USER_AGENT'] returns something like

Mozilla/4.0 (compatible; MSIE 5.5; CS 2000 6.0; Windows NT 5.0)


And I want to display that info as maybe...


Your ISP is AOL 6.0

etc...


get_broswer() was the closest I could find in the manuel,
but my host isnt set up for it and I was wondering if anyone knew another way.


Thanks

Virgil
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

The Internet Service Provider (ISP) or Host can not be determined from HTTP_USER_AGENT. This attempts to determine the capabilities of the user's browser. To determine the ISP of a user you must use gethostbyaddr which fetches the Internet host name corresponding to a given IP address.
Last edited by Kriek on Sun Jan 19, 2003 1:34 pm, edited 2 times in total.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

You will probably want to look into finding the ISP by means of the users IP, which can be found in

$_SERVER['REMOTE_ADDR'];
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

Code: Select all

<?php
$ip = $REMOTE_ADDR;
$host = gethostbyaddr($ip); 
$real_host=chop($host); 
if($real_host){ 
$host_arr=explode(".", $real_host); 
$count=count($host_arr); 
if($count > 1){ 
if(intval($host_arr[$count-1])!=0){ 
$host=substr($real_host,0,strrpos($real_host,".")).".*"; 
} 
else{ 
$host = "*".strstr($real_host, "."); 
} 
} 
else{ 
$host=$real_host; 
} 
} 
else{ 
$host=""; 
} ?>

Your IP address is <?php echo $ip; ?> | Your host is <?php echo $host; ?>
This takes the user's IP address with REMOTE_ADDR then using gethostbyaddr it returns thier host information.

Example: 242690hfc113.tampabay.rr.com

Then proceeds to clean up a little by removing their IP address from the host information.

Example: *.tampabay.rr.com

This would all return something like this.

Your IP address is 24.26.90.113 | Your host is *.tampabay.rr.com
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Post by virgil »

Thanks :D

In that case, if...

$_SERVER['HTTP_USER_AGENT']="Mozilla/4.0 (compatible; MSIE 5.5; CS 2000 6.0; Windows NT 5.0)";


I can just...

Code: Select all

<?
$host=$_SERVER&#1111;'HTTP_USER_AGENT'];
$host=strtr($host,")"," ");
$host=chop($host);
$host_array=explode(";",$host);

$browser=$host_array&#1111;1];
$isp=$host_array&#1111;2];
$opr_sys=$host_array&#1111;3];
?>
Your IP address is : <?=$_SERVER&#1111;'REMOTE_ADDR']?><br>
Your Browser is <?=$browser?><br>
Your ISP is <?=$isp?><br>
Your Operating system is <?=$opr_sys?><br>



I'll use ...

Code: Select all

$ip = $REMOTE_ADDR; 
$host = gethostbyaddr($ip);
...to store the actual isp.


Although, is there ever a time when $_SERVER['HTTP_USER_AGENT'] will return something with more or less elements?

I cant tell because I can only get my own info.

Does $_SERVER['HTTP_USER_AGENT'] consist of a multi-dimentional array whos elements can be accessed individually or is it just a string?


Again, Sincerest thanks for all your time and help.

PS I just had a friend try on a cable modem and the array elements are different. :( This will only work if I can access the $_SERVER['HTTP_USER_AGENT'] elements individually. Back to the drawing board...

Virgil
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

The variable HTTP_USER_AGENT will always return full and complete information, however it is possible to break it down incase you prefer to echo certain elements to the user such as the browser type only.

Code: Select all

<?php 
if(strstr($HTTP_USER_AGENT,"MSIE")) {
echo "You are using Internet Explorer<br>";
}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and keep in mind that HTTP_USER_AGENT is courtesy of the client. It's a normal http-request header and some browser allow to modify that string.
Post Reply