File tree 2 files changed +51
-4
lines changed
2 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -1094,6 +1094,7 @@ function activity()
1094
1094
1095
1095
$ this ->load ->helper ('ip ' );
1096
1096
$ this ->load ->helper ('date ' );
1097
+ $ this ->load ->helper ('session ' );
1097
1098
1098
1099
//获取记录
1099
1100
$ this ->db ->where ('operator ' , uid ());
@@ -1104,11 +1105,19 @@ function activity()
1104
1105
1105
1106
if ($ query ->num_rows () != 0 )
1106
1107
{
1107
- $ data = array ();
1108
+ $ sessions = array ();
1109
+
1108
1110
foreach ($ query ->result_array () as $ data )
1109
1111
{
1110
- //检查是否仍然在线
1111
1112
$ data ['value ' ] = json_decode ($ data ['value ' ], true );
1113
+
1114
+ //自CI 3.0起在同一浏览器上的多次登录可被登记为同一Session
1115
+ if (in_array ($ data ['value ' ]['session ' ], $ sessions ))
1116
+ continue ;
1117
+ else
1118
+ $ sessions [] = $ data ['value ' ]['session ' ];
1119
+
1120
+ //检查是否仍然在线
1112
1121
$ this ->db ->where ('session ' , $ data ['value ' ]['session ' ]);
1113
1122
$ check = $ this ->db ->get ('session ' );
1114
1123
@@ -1134,8 +1143,8 @@ function activity()
1134
1143
$ data ['current ' ] = true ;
1135
1144
1136
1145
//是否已经关闭
1137
- $ user_data = session_decode ($ session ['data ' ]);
1138
- if (! isset ($ user_data ['halt ' ]) || ! $ user_data ['halt ' ])
1146
+ $ user_data = session_unserialize ($ session ['data ' ]);
1147
+ if (isset ($ user_data ['logged_in ' ]) && $ user_data ['logged_in ' ])
1139
1148
$ active [] = $ data ;
1140
1149
}
1141
1150
}
Original file line number Diff line number Diff line change
1
+ <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
2
+
3
+ /**
4
+ * Session辅助函数
5
+ * @author Kaijia Feng <fengkaijia@gmail.com>
6
+ * @copyright 2019 Kaijia Feng
7
+ * @license Dual-licensed proprietary
8
+ * @link http://iplacard.com/
9
+ * @package iPlacard
10
+ * @since 2.3
11
+ */
12
+
13
+ /**
14
+ * 解析CodeIgniter序列化Session为数组
15
+ * @link https://www.php.net/manual/en/function.session-decode.php#108037
16
+ * @author Frits van Campen <Frits.vanCampen@moxio.com>
17
+ * @param string $session 序列化Session字符串
18
+ * @return array Session数组
19
+ */
20
+ function session_unserialize ($ session )
21
+ {
22
+ $ return = array ();
23
+ $ offset = 0 ;
24
+ while ($ offset < strlen ($ session ))
25
+ {
26
+ $ pos = strpos ($ session , '| ' , $ offset );
27
+ $ num = $ pos - $ offset ;
28
+ $ varname = substr ($ session , $ offset , $ num );
29
+ $ offset += $ num + 1 ;
30
+ $ data = unserialize (substr ($ session , $ offset ));
31
+ $ return [$ varname ] = $ data ;
32
+ $ offset += strlen (serialize ($ data ));
33
+ }
34
+ return $ return ;
35
+ }
36
+
37
+ /* End of file session_helper.php */
38
+ /* Location: ./application/helpers/session_helper.php */
You can’t perform that action at this time.
0 commit comments