1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

$$==== Grab the user agent of my website visitors ====$$

Discussion in 'Hire a Freelancer' started by wealth54, Oct 30, 2011.

  1. wealth54

    wealth54 Regular Member

    Joined:
    Jan 7, 2009
    Messages:
    313
    Likes Received:
    100
    Occupation:
    IM
    Location:
    PC
    I need a php or java coder to code an app or applet that will grab the user agent of my website visitors

    I already have a website I just need some sort of script that can be added to my site that will capture the user agent of my visitor.

    The user agent must be stored in a seperate file or database.

    Should be a simple task for the right canidate.

    send me PM asap
     
  2. webblackart

    webblackart Registered Member

    Joined:
    May 13, 2009
    Messages:
    60
    Likes Received:
    9
    javascript is not that easy, because its running client side so the script would not have the persmission to store any data on your server.
    Code:
    $sUseragent = $_SERVER['HTTP_USER_AGENT'];
    $oFile = fopen("useragents.txt","a");
    fwrite($oFile,$sUseragent + "\n");
    fclose($oFile); 
    
    this is the basic php code, it will append the useragent string to a text file when ever it is executed. only embedding this code to every page will lead into the problem that you will have as many entries in the text file as the user has requested a page with this code.
    so depending on your setup you should also store some additional information or make that code only execute once per session.
     
    Last edited: Oct 30, 2011
  3. kaidoristm

    kaidoristm Power Member

    Joined:
    Feb 13, 2009
    Messages:
    561
    Likes Received:
    726
    Occupation:
    Freelancer
    Location:
    Estonia
    Home Page:
    Basic as hell.

    PHP:
    <?php

    $user_agent_file 
    "user_agents.txt";

    if(isset(
    $_SERVER['HTTP_USER_AGENT']))
    {
        
    file_put_contents($user_agent_file$_SERVER['HTTP_USER_AGENT']."\r\n"FILE_APPEND LOCK_EX);
    }

    ?>