Hi,
I am seeking to get a solution for the foll. The only thing is I need an email to come to me as well as the data going into a db table.
I need to know :
1) What IP's accessed the site, when the came on and where they went
2) Whic users logged on, when he logged on and what pages they viewed/actions they did
For 1) above I have the foll. code for when they came on but not where they went. I created a protect.php file as under. But i cannot figure out what to do for 2) above.
I also need local time coming up not server time.
Any suggestions ?
Thanks !
CODE
if ($action == "logout")
{
Setcookie("logincookie[pwd]","",time() - 3600);
Setcookie("logincookie[user]","",time() - 3600);
include($logout_page);
exit;
}
else if ($action == "login")
{
if (($loginname == "") || ($password == ""))
{
include($invalidlogin_page);
exit;
}
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql = "SELECT * FROM users WHERE username='$loginname' ";
$result = mysql_query($sql)
or die ("Unable to get results.");
$myrow = mysql_fetch_array($result);
if (strcmp($myrow["password"],$password) == 0)
{
Setcookie("logincookie[pwd]",md5($password),time() + 3600);
Setcookie("logincookie[user]",$loginname,time() + 3600);
$dd = date("d F Y");
$ddd = date("Hi");
$to_mail = "abi@def.com";
$subject = "".$loginname." logs in";
$message = "
user ".$loginname." logged in on ".$dd." at ".$ddd."HOURS (server time) from IP Address: ".$HTTP_SERVER_VARS["REMOTE_ADDR"];
$from_mail = "xyz@def.com";
$headers = "From: $from_mail\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail( $to_mail, $subject, $message, $headers );
}
else
{
include($invalidlogin_page);
exit;
}
}
else
{
if (($logincookie[pwd] == "") || ($logincookie[user] == ""))
{
include($login_page);
exit;
}
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");
mysql_select_db($database)
or die ("Unable to select database.");
$sql = "SELECT * FROM users WHERE username='$logincookie[user]' ";
$result = mysql_query($sql)
or die ("Unable to get results.");
$myrow = mysql_fetch_array($result);
if (strcmp(md5($myrow["password"]),$logincookie[pwd]) == 0)
{
Setcookie("logincookie[pwd]",$logincookie[pwd],time() + 3600);
Setcookie("logincookie[user]",$logincookie[user],time() + 3600);
}
else
{
include($invalidlogin_page);
exit;
}
}
?>
<?php
function calculatedate($inputdate)
{
$inputdate_parts = explode('-', $inputdate);
if ($inputdate_parts[1]==00 && $inputdate_parts[2]==00 && $inputdate_parts[0]==0000)
return ' ';
// Calculating the UNIX Timestamp for both dates
$x = mktime(0, 0, 0, $inputdate_parts[1], $inputdate_parts[2], $inputdate_parts[0]);
$outputdate = date('d.m.y', $x);
return $outputdate;
}
?>
swati