-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.php
81 lines (69 loc) · 1.91 KB
/
Log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
session_start();
require_once("database.php");
require_once('DBsettings.php');
//IP
if (!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}else{
$ip = $_SERVER["REMOTE_ADDR"];
}
echo "YOUR IP IS:".$ip."</br>";
if ($_SESSION['Permission']==1){
//計數器
//變量$n是顯示位數
$n=8;
if (file_exists("counter.txt"))
{
//只讀方式打開type01_counter.txt文件
$counterfile=fopen("counter.txt","r");
//讀取4位數字
$counter_num=fgets($counterfile,$n+1);
//關閉文件
fclose($counterfile);
}
else
{
$counter_num=1;
}
echo "<font color='purple'><b>"."截至".date('Y-m-d H:i:s')."總共有 ".$counter_num . "次登入</font></br>";
// Load settings from parent class
$settings = DatabaseSettings::getSettings();
// Get the main settings from the array we just loaded
$host = $settings['dbhost'];
$name = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];
$conn = new PDO("mysql:host=$host;dbname=$name", $user, $pass);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "登入情形: </br>";
$sql = "SELECT * FROM Log";
//執行並查詢,查詢後只回傳一個查詢結果的物件,必須使用fetc、fetcAll...等方式取得資料
$result = $conn->query($sql);
echo "<table border='1'>";
$i = 0;
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
if ($i == 0) {
$i++;
echo "<tr>";
foreach ($row as $key => $value) {
echo "<th>" . $key . "</th>";
}
echo "</tr>";
}
echo "<tr>";
foreach ($row as $value) {
echo "<td>" . $value . "</td>";
}
echo "</tr>";
}
echo "</table>";
}
else{
echo "訪客請移駕";
}
?>