duanhuang3074 2012-08-27 09:06
浏览 114

每次用户登录时记录用户的IP地址 - PHP

Here are my codes from the login page. I want to be able to count how many times have been using my website and also where they logged in from. I am able to do the count, but not the ipaddress.

In the table, I want it show each user data like this

These are the columns in my table. USERNAME, LAST LOGGED IN, TIMES LOGGING IN, IPADDRESS, IPADDRESS1, IPADDRESS, ...... IPADDRESS10. I have created all 10 different ip address columns ( I am not really sure how to make the followings looks like they are in the table, so I am really sorry )

USERNAME | LAST LOGGED IN | TIMES LOGGING IN | IPADDRESS | IPADDRESS1 | IPADDRESS2 ...... | IPADDRESS10

IHOP | 21-12-2012 8.59PM | 5 | 80.81.82.83 | 80.81.82.82 | 80.81.82.83

Every time a new ip address was used to log in from the same user, the ip address will be record into the table. Each user has up to 10 different ip addresses. The table is from my first thought, so I am not really sure if it's the best way to show them in the table or not, so please also give me a recommendation.

How do I add these ip addresses in to the table? I am not really sure how to separate each ip address column. When I got the new ip address, it just keeps overwriting the old ip address.

Thank you very much.

var $HOST = "website.com";  
var $USERNAME = "username"; 
var $PASSWORD = "password"; 
var $DBNAME = "database";   

function authenticate($username, $password) {

$Auth = new auth();
$detail = $Auth->authenticate($username, $password);

    if (ereg("'", $username)) 
    {
        return "invalid username";
    }

    if (ereg("'", $password)) 
    {
        return "invalid password";
    }

    $query = "SELECT * FROM user WHERE uname='$username' AND passwd=MD5('$password') AND status <> 'inactive'";

    $UpdateRecords = "UPDATE user SET lastlogin = NOW(), logincount = logincount + 1 WHERE uname='$username'";
    $connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD);

    $SelectedDB = mysql_select_db($this->DBNAME);
    $result = mysql_query($query); 

    $numrows = mysql_num_rows($result);
    $row = mysql_fetch_array($result);

    if ($numrows == 0) {
        return 0;
    }

    */
    else {
        $Update = mysql_query($UpdateRecords);
        return $row;
    }
  • 写回答

3条回答 默认 最新

  • duanniling0018 2012-08-27 09:10
    关注

    It would be a better idea to have a separate table with (USERNAME | IPADDRESS | TIME) columns. That way, you will be able to store more effectively (and easily) different IP adress for a given user. Then, you'll have to choose an algorithm to retain these informations (keep first 10 different IP adress ? keep last 10 ?...)

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决