Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Logging ip addresses

  • 22-03-2004 01:12PM
    #1
    Registered Users, Registered Users 2 Posts: 986 ✭✭✭


    i have a small website, but i want to track ip address as people use the message board on the site, eg when they click the submit button or when they enter the message board page, how can i do this?


Comments

  • Closed Accounts Posts: 1,163 ✭✭✭Emboss


    if you're using PHP look into REMOTE_ADDR


  • Registered Users, Registered Users 2 Posts: 23,202 ✭✭✭✭Tom Dunne


    Isn't that info stored in the Web servers logs? I remember from my Apache days seeing ip addresses which accessed the site in the log files. Try looking in there.


  • Registered Users, Registered Users 2 Posts: 986 ✭✭✭wild_eyed


    i am getting thefollowing error on the second line of this code
    Parse error: parse error in /home/www/web277/web/postform.php on line 45

    i.e. line 45 of the entire page = line 2 of this code.

    can anyone tell me whats wrong.

    noob.


    [PHP]<?
    $ip = $_SERVER;
    $logged_string = $ip . "|" . . date("j M Y g:i a");
    $file = fopen("userIP.log", "a");
    fputs($file, $logged_string, strlen($logged_string));
    fclose($file);
    ?> [/PHP]


  • Registered Users, Registered Users 2 Posts: 2,206 ✭✭✭Serbian


    [PHP]<?
    $ip = $_SERVER;
    $logged_string = $ip . "|" . /* extra dot here -> */ . date("j M Y g:i a");
    $file = fopen("userIP.log", "a");
    fputs($file, $logged_string, strlen($logged_string));
    fclose($file);
    ?> [/PHP]


  • Registered Users, Registered Users 2 Posts: 986 ✭✭✭wild_eyed


    sorry, do u mean that i shud place an extra dot were the comments are?

    like this?

    [PHP]
    <?
    $ip = $_SERVER;
    $logged_string = $ip . "|" . . . date("j M Y g:i a");
    $file = fopen("userIP.log", "a");
    fputs($file, $logged_string, strlen($logged_string));
    fclose($file);
    ?>
    [/PHP]


  • Advertisement
  • Closed Accounts Posts: 304 ✭✭Zaltais


    Originally posted by wild_eyed
    sorry, do u mean that i shud place an extra dot were the comments are?

    like this?


    No he means you have an extra dot. It should be ->

    [PHP]
    <?
    $ip = $_SERVER;
    $logged_string = $ip . "|" . date("j M Y g:i a");
    $file = fopen("userIP.log", "a");
    fputs($file, $logged_string, strlen($logged_string));
    fclose($file);
    ?>
    [/PHP]


  • Registered Users, Registered Users 2 Posts: 2,206 ✭✭✭Serbian


    As above. Sorry, I should have just posted the correct code instead of putting that comment in there :p.


  • Registered Users, Registered Users 2 Posts: 986 ✭✭✭wild_eyed


    thanks is working grand, one thinbg though, it's placing all the log entries on the same line, how can i make it start a new line for each entry?


  • Registered Users, Registered Users 2 Posts: 2,206 ✭✭✭Serbian


    Try the following:
    [PHP]
    <?
    $ip = $_SERVER;
    $logged_string = $ip . "|" . date("j M Y g:i a") . "\r\n";
    $file = fopen("userIP.log", "a");
    fputs($file, $logged_string, strlen($logged_string));
    fclose($file);
    ?>
    [/PHP]


Advertisement