Hi,
I created a new table in mysql db called Log and added the foll fields:
a. ID(Primary key, autoincrement)
b. Userid
c. IP
d. Date (DateTime type)
e. File
Now, all my php files have the foll. as the 1st line :
<? include (protect.php) ?>
protect.php is below. As you can see, once a user has logged in, the Sql statement has nothing more to do and it is of use only to the dbname and dbpwd. Where do I create another sql statement that gets queried each time a php file is requested. What do I add there so that the required info. gets filled into the Log Table as described above ?
Thanks in advance for your guidance
<?
// This is the page to show when the user has been logged out
$logout_page = "logout.php";
$dbname = "$$$";
$dbpasswd = "$$$";
$database = "$$$";
// Page with login form
$login_page = "login.php";
// Page to show if the user enters an invalid login name or password
$invalidlogin_page = "invalidlogin.php";
//DON'T EDIT ANYTHING BELOW THIS!!!
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);
}
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;
}
?>