Page 1 of 1
Determine ISP?
Posted: Sun Jan 19, 2003 12:03 pm
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
Posted: Sun Jan 19, 2003 1:05 pm
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.
Posted: Sun Jan 19, 2003 1:08 pm
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'];
Posted: Sun Jan 19, 2003 1:10 pm
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
Posted: Sun Jan 19, 2003 3:33 pm
by virgil
Thanks
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ї'HTTP_USER_AGENT'];
$host=strtr($host,")"," ");
$host=chop($host);
$host_array=explode(";",$host);
$browser=$host_arrayї1];
$isp=$host_arrayї2];
$opr_sys=$host_arrayї3];
?>
Your IP address is : <?=$_SERVERї'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
Posted: Sun Jan 19, 2003 4:00 pm
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>";
}
?>
Posted: Sun Jan 19, 2003 4:34 pm
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.