1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Browser, IP and Hostname Displaying Php Code

Discussion in 'PHP' started by Bhuntay, Sep 16, 2008.

  1. #1
    I searched for google and got few codes but I am not able to put them in my site. I want a free code that detects Browser, IP and Hostname of the visitor and display is. I am total newbie so please give me the code in a manner that would be just copy paste ready :)
    Thank You.
     
    Bhuntay, Sep 16, 2008 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    to get the IP

    <?php
    echo $_SERVER['REMOTE_ADDR'];
    ?>

    get the browser
    <?php
    echo $_SERVER['HTTP_USER_AGENT'];
    ?>

    hmm for the third one (hostname). i dont know wat this is..
    give some example of it?
     
    bartolay13, Sep 16, 2008 IP
    Bhuntay likes this.
  3. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Great thanks for these two codes, :) Will wait for someone to post the third code :) Rep Added +
     
    Bhuntay, Sep 16, 2008 IP
  4. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here is the script with all your needs. :)

    
    <?php
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
    {
       if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape') )
       {
         $browser = 'Netscape (Gecko/Netscape)';
       }
       else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') )
       {
         $browser = 'Mozilla Firefox (Gecko/Firefox)';
       }
       else
       {
         $browser = 'Mozilla (Gecko/Mozilla)';
       }
    }
    else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
    {
       if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') )
       {
         $browser = 'Opera (MSIE/Opera/Compatible)';
       }
       else
       {
         $browser = 'Internet Explorer (MSIE/Compatible)';
       }
    }
    else
    {
       $browser = 'Others browsers';
    }
    
    if ($_SERVER['HTTP_X_FORWARD_FOR']) {
    $ip = $_SERVER['HTTP_X_FORWARD_FOR'];
    } else {
    $ip = $_SERVER['REMOTE_ADDR'];
    }
    
    $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    
    echo "Hello Visitor, here is your Info:<br><br>";
    
    echo "You are using: " . $browser . "<br>";
    
    echo "Your IP is: " . $ip . "<br>";
    
    echo "Your Hostname is: " . $hostname;
    
    ?>
    
    PHP:
     
    mehdi, Sep 16, 2008 IP
    Bhuntay likes this.
  5. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you very much mehdi :) I added you a reputation. Also I am looking for a free script with no link back which shows a beautiful Country flag of the visitors :) Also if there's any script to find the User's ISP details. It would be great if you help me again in these matters :)
     
    Bhuntay, Sep 16, 2008 IP
  6. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    mehdi, Sep 16, 2008 IP
  7. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I was looking for same but free, totally free :D
     
    Bhuntay, Sep 16, 2008 IP
  8. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    mehdi, Sep 16, 2008 IP
  9. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #9
    I would use the following for IP, it tends to work better.

    <?
    $ip = (getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR):getenv(REMOTE_ADDR);
    echo $ip;
    ?>
    
    PHP:
     
    nabz245, Sep 16, 2008 IP
  10. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #10

    Hey mehdi you are the man, this is what I have been looking for. I am very grateful to you, your a very useful person :) Thank you so so so much with all my heart with all my spirit :)

    God Bless.
     
    Bhuntay, Sep 17, 2008 IP
  11. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thank you mate! :)
     
    mehdi, Sep 18, 2008 IP
  12. Bhuntay

    Bhuntay Banned

    Messages:
    837
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Anytime Mehdi, this is where I used the code Site here
     
    Bhuntay, Sep 18, 2008 IP