Old 06-28-2005   #1 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Simple User Info - Beta Testing

Over the past couple of days i've been working on a little script that get the users IP, Host, and browsing agent. Getting the IP was failrly simple, the host, was a little trickier bcuz I was using REMOTE_HOST for awhile (which was returning nothing) until I read a few things about gethostbyaddr().

The main issue here, is the get_browser() function. So far, it works great and as far as I know it supports 7 different browsers (read the commenting in the script).

I'm looking for as many people as possible to test my script by going here or you can copy/paste the entire script below and test it on your own server/etc.

Please tell me of any bugs/suggestions that you find/think of. Also, if this script detects you browser correctly (and I don't have it under "tested browsers") then please let me know and I will add it to the list.

This script may be used/distributed to anyone if and Only if it is fully credited to me and whom ever else helped create/beta test it (which is shown in the script comments).

Enjoy!
PHP Code:
<?php
/*-------------------------------------------------------------
    Created by: Ryan Miller
    Started on: Monday, June 27, 2005
    Last modified: June 29, 2005
    Copyright 2005+ All Rights Reserved.
    
    Features:  Gets IP and Host from IP.
               Will return a User ID which is IP@HOST
               Returns a browsing agent that the user
               is currently using.
    Note: Not all browsers have been tested.
          Current tested browsers include:
            Mozilla Firefox v0.10.1
            IE v6.0
            Opera / Opera 8.01  (Thanks ParaSnake!)
    Note#2: Currently, only mozilla firefox and 
            Opera 8.01 agents will return with a version.
    Special Thanks:
        The Online PHP Manual
        www.BioRUST.com | www.forums.biorust.com
    
    ChangeLog -
                v1.0.1 - Added error handling for browser agent.
                       - Removed unnecessary code in get_browser()
                       - Fixed ID support for future MySQL DB handling
                         and printing.
                         
                v1.0.2 - Added full agent display, for testing
                       - Changed unit strings to bold
                       
                v1.0.3 - Added support for Opera 8.01
                       - Changed the order in which the browser is
                         detected. (opera 8.01 is now checked first)
                v1.0.4 - Added support for Maxthon browsers.
                           
---------------------------------------------------------------*/
 
function get_user_info()
{   
$ip trim($_SERVER['REMOTE_ADDR']);
     if(
$ip === false)
        { return 
false; }
    
$host gethostbyaddr($ip);
     if(!
$host)
        { 
$host 'Unkown'; }
    
// print info out
    
print '<strong>User ID:</strong> '.$ip;
     if(
$host)
        { print 
'@'.$host.'<br>'; }
     
//display browser/ver
     
$bInfo browser_info();
      if(
$bInfo === false)
        { print 
'<script>alert("Your browsing agent could not be detected. This very well could be a script bug/error.  Please notify the script creator for further info and help.");</script>';
        }
    return 
true;
}

function 
browser_info()
# Checks for:
  #   Opera    (opera 8.01, opera)
  #   Maxthon  (maxthon)  
  #   IE       (msie, internet explorer)
  #   Firefox  (firefox)
  #   Konqeror (konqeror)
  #   Lynx     (lynx)
  #   Netscape (mozilla)          
    
$agent trim($_SERVER['HTTP_USER_AGENT']);
     if(!
$agent)
     { return 
false; }
    
    
//get opera 8.01 and version
    
if(stristr($agent,'opera 8.01'))
        {   
$id      1;
            
$browser 'Opera';
            
$ver     'v8.01';
        }
    elseif(
stristr($agent,'opera'))
        {   
$id      1;
            
$browser 'Opera';
        }
    elseif(
stristr($agent,'maxthon'))
        {   
$id      2;
            
$browser 'Maxthon';
        }
    elseif(
stristr($agent,'msie'))
        {   
$id      3;
            
$browser 'Microsoft IE';
        }
    elseif(
stristr($agent,'internet explorer'))
        {   
$id      3;
            
$browser 'Microsoft IE';
        }    
    elseif(
stristr($agent,'firefox'))
        {   
$id      4;
            
$browser 'Mozilla Firefox';
            
// get version
            
$str  stristr($agent,'firefox');
            
$bArr explode('/',$str);
            
$ver  $bArr[1];
        }
    elseif(
stristr($agent,'konqeror'))
        {   
$id      5;
            
$browser 'Konqeror';
        }
    elseif(
stristr($agent,'lynx'))
        {   
$id      6;
            
$browser 'Lynx';
        }
    elseif(
stristr($agent,'mozilla'))
        {   
$id      7;
            
$browser 'Netscape';
        }
    else
        { 
$browser 'Unknown'; }
    
    
// print agent for firefox/opera 8.01 (agent/version).
    
if((($id) && ($id == 1)) || (($id) && ($id == 4)))
        { print 
'<strong>Browser:</strong> '.$browser.' v'.$ver.'<br>'; }
    
// print for all other agents (agent)
    
elseif((!$id) || ($id != 4))
        { print 
'<strong>Browser:</strong> '.$browser.'<br>'; } 
    
}
// print user info.  If ip is not true, print error.
$user_info get_user_info();
if(!
$user_info)
    { print 
'<script>alert("It appears your IP address was unable to be found. Please notify the script creator for further info and help.");</script>';
      exit;
    }
// print full agent
print '<br><strong>Agent:</strong> '.$_SERVER['HTTP_USER_AGENT'].'<br>';
?>

Last edited by ViciOuS; 06-30-2005 at 03:13 PM. Reason: Script change v1.0.2
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-29-2005   #2 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
It doesnt work with Opera 8.01 hehe,how can Opera be IE???
I suggest you use javascript to detect browser,its better and much more sensivitive than PHP`s function.
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-29-2005   #3 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

hmm, i'm not very familiar with that much js. I was just making this for a few systems that require it. All I need is to beta test most common browsers with this script and fix/add any bugs/mods.

Anyways, click on the script link again and there should be a new unit labled Agent. Copy and Paste what the Agent is and i'll see what i can do to detect opera 8.01.

If you have any other browsers that havent been tested with this script let me know or try them with the script and give me the results.

- Thanks in advance
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-29-2005   #4 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.01

hehe,its the same as what JS do ^^
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-29-2005   #5 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

OK!

Now test the script and tell me what the browser says. Opera 8.01 is checked first now (in v1.0.2 and lower, IE was checked first.)

It also checks for a regular Opera (without any version), which still hasn't been tested yet.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-30-2005   #6 (permalink)
Invicible Snake
 
ParaSnake's Avatar
 
Join Date: Sep 2004
Location: Ho Chi Minh City,Vietnam
Posts: 668

Send a message via MSN to ParaSnake Send a message via Yahoo to ParaSnake
works well
congratz
__________________
ParaSnake is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 06:53 PM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT