Log ip in a file and display a message

Discussion in 'PHP' started by ASTRAPI, Oct 11, 2008.

  1. #1
    Hi

    I was move to another directory the acp from my invision forum and i want when a user goes to:

    http://www.myforum/admincp/
    Code (markup):
    To get the ip from the user plus time in a file and display a message like i have your ip bla bla .....

    Thanks
     
    ASTRAPI, Oct 11, 2008 IP
  2. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I don't really get what do you want.
    Can you please explain more detail?

    You want to redirect all users who accessed your ACP except yourself?
     
    djzmo, Oct 11, 2008 IP
  3. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No

    I need when a user goes to:
    http://www.myforum/admincp/
    
    Code (markup):
    that does not exist at all to put a file there and gets the ip from the user that was trying to open that directory so i will know who is trying to find my acp.
     
    ASTRAPI, Oct 11, 2008 IP
  4. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Simplified:
    $ip = getenv("REMOTE_ADDR");
    $logfile = "ip_log.txt";
    $file = fopen($logfile, 'w') or die("Failed to open logfile");
    fwrite($file, $ip . '\n');
    fclose($file);
    PHP:
    IPs will be separated by a new line.
     
    djzmo, Oct 11, 2008 IP
  5. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Does that log also the time that the user try to find my acp?

    And also how can i display a message to him e.x: I have your ip bla bla

    Thanks
     
    ASTRAPI, Oct 11, 2008 IP
  6. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #6
    $ip = getenv("REMOTE_ADDR");
    $logfile = "ip_log.txt";
    $file = fopen($logfile, 'w') or die("Failed to open logfile");
    fwrite($file, $ip . '|' . date('r') . '\n');
    fclose($file);
    print "I have your ip bla bla";
    PHP:
    Log format:
    IP-address|time-logged
    IP-address|time-logged
    IP-address|time-logged
    ...
    Code (markup):
     
    djzmo, Oct 11, 2008 IP
  7. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you :)


    Is this code secure?

    For r.f.i or any other security exploits?


    Ok i add the code to a file named admincp.php in a folder /admincp/ and i add also a file named: ip_log.txt

    But when i try to go to the
    www.myserver.com/admincp/
    Code (markup):
    i get this:

    Forbidden

    You don't have permission to access /admincp/ on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

    Why it doesn't run the php file?
     
    ASTRAPI, Oct 12, 2008 IP
  8. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    perhaps rename admincp.php to index.php...?
     
    Pos1tron, Oct 12, 2008 IP
  9. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yes you are write :)

    but now i can see this:

    $ip = getenv("REMOTE_ADDR"); $logfile = "ip_log.txt"; $file = fopen($logfile, 'w') or die("Failed to open logfile"); fwrite($file, $ip . '|' . date('r') . '\n'); fclose($file); print "I have your ip bla bla";

    And i don't get any log in the txt file :(

    admincp directory : attributes 755
    index.php file : attributes 644
    ip_log.txt file : attributes 777

    ?
     
    ASTRAPI, Oct 12, 2008 IP
  10. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #10
    you forgot php tag

    <?php
    $ip = getenv("REMOTE_ADDR");
    $logfile = "ip_log.txt";
    $file = fopen($logfile, 'w') or die("Failed to open logfile");
    fwrite($file, $ip . '|' . date('r') . '\n');
    fclose($file);
    print "I have your ip bla bla";
    ?>
    PHP:
     
    ads2help, Oct 12, 2008 IP
  11. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks working great now :)

    1)At the end of log i get this:

    -0600\n

    What is this?

    2)Is this php file (code) secure for rfi ,lfi,exploits?

    3)Also i just notice that logs the first user and then when someone else goes there it replace the first line :(

    It doesn't go to the next line like this:

    IP-address|time-logged
    IP-address|time-logged
    IP-address|time-logged
    ...

    Only one line and then replace this line with the info from the next user.

    Thanks for your help
     
    ASTRAPI, Oct 12, 2008 IP
  12. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #12
    <?php
    $ip = getenv("REMOTE_ADDR");
    $logfile = "ip_log.txt";
    $prev_content = @file_get_contents($logfile);
    $file = fopen($logfile, 'w') or die("Failed to open logfile");
    fwrite($file, $prev_content . $ip . '|' . date('r') . '
    ');
    fclose($file);
    print "I have your ip bla bla";
    ?>
    PHP:
     
    djzmo, Oct 12, 2008 IP
  13. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #13
    I Wouldnt recommend adding

    print "I have your ip bla bla";
    Code (markup):
     
    Bohra, Oct 13, 2008 IP
  14. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #14
    Should be secure because it does not take any _get variable or what.

    $ip = getenv("REMOTE_ADDR");
    $logfile = "ip_log.txt";
    $prev_content = @file_get_contents($logfile);
    $file = fopen($logfile, 'w') or die("Failed to open logfile");
    fwrite($file, $prev_content . $ip . "   |   " . date('r') . "\r\n");
    fclose($file);
    print "I have your ip bla bla";
    PHP:
    -0600 ? That is your server's time & timezone. -0600 should be GMT-6.
     
    ads2help, Oct 13, 2008 IP
  15. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15

    Why?

    All working great :)
     
    ASTRAPI, Oct 13, 2008 IP
  16. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #16
    maybe they will feel like you are challenging them? =D
     
    ads2help, Oct 13, 2008 IP
  17. JBrace1990

    JBrace1990 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    you should change your 404 error page to this if you want to log everything. Then also add in the page they were trying to get.
     
    JBrace1990, Oct 13, 2008 IP
  18. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Ok thanks :)
     
    ASTRAPI, Oct 13, 2008 IP
  19. thegussey

    thegussey Peon

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    hi actually i can't open
    http://www.myforum/admincp/
    Code (markup):
    :)
     
    thegussey, Oct 14, 2008 IP