PHP中的用户登录历史记录

时间:2013-09-23 05:24:09

标签: php mysql

我想拥有一个用户登录历史文件,我已经拥有用户登录的时间。为了让我只查询我网站的所有行,还有什么我需要添加的吗?

我有成员表和管理员表,他们存储了用户名和信息。在我的管理页面中,我想列出与他们登录时间对应的member_fn及其member_ID。这是我登录的php:

include("conn.php");

$un = $_POST["user"];
$pw = $_POST["pass"];

$encpass = md5($pw);

if(empty($un))
{
    header("refresh:;url=login.php");
}
else if (empty($pw))
{
    header("refresh:;url=login.php");
}
else
{
     $sql= mysql_query("SELECT * FROM $table WHERE member_un='".$un."' AND member_pw='".$encpass."' ");
     $sql1=mysql_query("SELECT * FROM admin WHERE admin_un='".$un."' AND admin_pw='".$pw."'");
     $numrow = mysql_num_rows($sql);
     $numrow2=mysql_num_rows($sql1);    


if ($numrow!=0)
{

    if($row=mysql_fetch_array($sql))
    {           
            $query=mysql_query("UPDATE $table SET member_count=(member_count+1) WHERE member_un='".$un."'");
            if($query){
            //  echo "Welcome " . $row['member_fn'];

                header("Location:main.php");
            }
        $_SESSION['fn'] = $row['member_fn'];
    }
    else
    echo"wrong password";

}
else if($numrow2!=0)
    {
        if($row=mysql_fetch_array($sql1))
            {
                $_SESSION['fn'] = $row['admin_fn'];
                $_SESSION['un'] = $row['admin_un'];
                header("Location:admin.php");
            }
    }


else
echo("That user does not exists");
header( "refresh:5;url=login.php" ); 
}

和我的管理页面:

    include("conn.php");

    $fn=$_SESSION['fn'];    

    $result = mysql_query("SELECT count(member_ID) as member_ID FROM $table");

    echo "Registered Members: ";
    while ($row = mysql_fetch_array($result)) {
        echo $row['member_ID'];

       }

     $sql = mysql_query("SELECT * FROM member");
     echo "<br>User Login History: ";
     while($row = mysql_fetch_array($sql))
     {  // some code to list all the usernames from member table
        echo $row['member_count'];
        echo $row['member_ID'];
        echo $row['member_fn']."<br>";

     }

我知道应该有一个代码来重复显示我的登录历史记录的所有用户名,但我不知道应该在那里写什么。有没有办法显示所有重复登录的用户?非常感谢你。

0 个答案:

没有答案