Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

.htpasswd & .htaccess user log


ghost's Avatar
0 0

Is it possible to log anybody that logs in the password protected area (by .htpasswd) of my website, and store the info in some file located on the server?

Like :

log.txt

Cynoxx logged at 9:00 AM. IP: 127.0.0.1 etc..etc..

Is that possible?

EDIT : If it is, how :P?


ghost's Avatar
0 0

I'm pretty sure it is but get a second opinion.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

Hey cynoxx, long time no see, if you use cpanel you can get the raw access logs, then view who accessed files


ghost's Avatar
0 0

Put the following code in the index.php of the protected dir:

<?
$ip=$_SERVER['REMOTE_ADDR'];
$file="log.txt";
$fp = fopen ("$file", "a+"); 
$time= date(' l ds &*92;of F Y h:i:s A') // This will output the date in the format: Friday 26th of May 2006 01:59:25 PM ;
$content= "$ip logged in at $time &*92;n";
fwrite($fp, $content);
fclose($fp);
?>

NOTE: The &*92; is supposed to be a backslash


ghost's Avatar
0 0

Yeah I havent been on for ages! Yeah it's not a forum or anything, so no cpanel.

^I will try that and see if it works thanks alot!


ghost's Avatar
0 0

markupParse error: syntax error, unexpected T_VARIABLE in /hd2/djcsites/******/******/index.php on line 6

I get this… any ideas? I tried with the backslashes, and it doesnt work either :(.


ghost's Avatar
0 0

you need a ; after the $date line, it's commented out


ghost's Avatar
0 0

No more errors, thanks!


ghost's Avatar
0 0

It might be hard, but is there a way to log which user from my .htpasswd file logged in?


ghost's Avatar
0 0

system_meltdown wrote: Hey cynoxx, long time no see, if you use cpanel you can get the raw access logs, then view who accessed files

Almost everything cPanel does is provide an interface for already-existing daemons and such.

You can do that without cPanel if you run your own server.


ghost's Avatar
0 0

Cynoxx_ wrote: It might be hard, but is there a way to log which user from my .htpasswd file logged in?

anyone?