23 เมษายน 2555

การทำ LOG USER เมื่อ User LOGIN เข้าใช้งาน ใน PHP

Step.1 สร้างฐานข้อมูล
CREATE TABLE `db_userlog` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`username` char(6) DEFAULT NULL,
`userip` char(15) DEFAULT NULL,
`logindate` datetime DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

Step 2. เพิ่มโค้ดบรรทัดนี้
mysql_query("insert db_userlog(username,userip,logindate) values('".$_SESSION["user_name"]."','".$_SERVER['REMOTE_ADDR']."','".date('Y-m-d H-i-s')."')");
ลงในไฟล์ Login เมื่อเข้าสู่ระบบได้
Step 3. โค้ดสำหรับแสดงข้อมูล รายวัน รายเืดือน รายปี
require('connect.php');
echo '<br/>วันนี้ :'.showsumlog_less(date("Y-m-d", strtotime("today")));
echo '<br/>เมื่อวานนี้ :'.showsumlogl_between(date("Y-m-d", strtotime("-1day")),date("Y-m-d", strtotime("today")));
echo '<br/>สองวันนี้ :'.showsumlog_less(date("Y-m-d", strtotime("first day of this month")));
echo '<br/>เดือนนี้ :'.showsumlog_less(date("Y-m-d", strtotime("first day of this month")));
echo '<br/>รอบสามสิบวัน:'.showsumlog_less(date("Y-m-d", strtotime("-30day")));
echo '<br/>รอบหกสิบวัน:'.showsumlog_less(date("Y-m-d", strtotime("-60day")));
echo '<br/>ปีนี้:'.showsumlog_less(date("Y-m-d", strtotime("first day of January this Year")));
echo '<br/>ปีนี้ที่แล้ว:'.showsumlogl_between(date("Y-m-d", strtotime("first day of january last Year")),date("Y-m-d", strtotime("first day of January this Year")));
mysql_close($con);

ไม่มีความคิดเห็น: