Skip to content

Instantly share code, notes, and snippets.

@binarybucks
Created September 14, 2014 16:24

Revisions

  1. Alexander Rust created this gist Sep 14, 2014.
    13 changes: 13 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?php

    if ($_SERVER["HTTP_X_FORWARDED_FOR"] != "") {
    $IP = $_SERVER["HTTP_X_FORWARDED_FOR"];
    $host = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]);
    } else {
    $IP = $_SERVER["REMOTE_ADDR"];
    $host = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
    }
    header('Content-Type: application/json');
    echo json_encode(array('ip' => $IP, 'host' => $host, 'userAgent' => $_SERVER["HTTP_USER_AGENT"]), JSON_PRETTY_PRINT);

    ?>