-1

I have a page that I had to make a custom lock on because I use a service where you need premium for locking pages so I made my own HTML lock which works. What I do not completely trust is how secure it is, so I would like to make some code where when the user gets the password correct, it logs their IP address and the time that they logged in.

I have only three people that should have access to this page so it will be easy to see an IP that should not be there. I want the code to log the IP to a file that would be easy to access for me such as logins.html that I could check and see the IPs of people that have logged in. I do not know if this is possible and help would be great, thanks!

-wdmc85

[Edit]: Or how could I do this with PHP?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • You can't do that with Javascript. Just use PHP or another dynamic technology on the server and log it there. An HTML lock also is inherently insecure, use server-side scripting for that as well. – nanofarad Jun 28 '13 at 01:26
  • 1
    There's no notion of hosts or ip-addresses in the javascript standard library. So you'll have to access some external service to look up hostnames for you. Try researching though, there are numerous posts on SO already about this issue. – Dan675 Jun 28 '13 at 01:26
  • @ObsessiveSSOℲ how could i write this in php because i know it is not all that secure but that is why i want to see who gets on there. people can crack anything but if i look at who gets on i will know when to change the password – user1493374 Jun 28 '13 at 01:35
  • @user1493374 If the platform is very secure with a powerful password and proper cryptography (and the user isn;t clumsy) there should be no security issues. Please search first, instead of personally pinging me. I'm not the only person on this site potentially capable of answering. – nanofarad Jun 28 '13 at 01:37
  • 1
    its not secure, ip!=person –  Jun 28 '13 at 01:55
  • @user1493374 *"Almost"* Anything is possible, if you put your mind to it. ;-) – Funk Forty Niner Jun 28 '13 at 02:18

2 Answers2

2

This should get you on the way:

<?php
 //this will get your ip
 $this_is_the_ip = $_SERVER['REMOTE_ADDR'];

 //write to some file, this will write to the directory where this executes
 file_put_contents("access-log.txt", $this_is_the_ip . "\n", FILE_APPEND);
?>

maybe put this right after the block of code that checks the password submit.

Matthew Graves
  • 3,226
  • 1
  • 17
  • 20
0

Seems like this has the answer: How to get client's IP address using javascript only?

Bear in mind that the javascript on your page can easily be disabled/manipulated and shouldn't be relied on for security.

Community
  • 1
  • 1
Ed W
  • 125
  • 3
  • 18