Skip to content

Commit 2aceae7

Browse files
author
Yaroslav Vodvud
committed
fixed Multiple Sessions bug
1 parent 4a1bef1 commit 2aceae7

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

zklib/ZKLib.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,13 @@ public function _command($command, $command_string, $type = Util::COMMAND_TYPE_G
5555

5656
$u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($this->_data_recv, 0, 8));
5757

58-
switch ($type) {
59-
case Util::COMMAND_TYPE_GENERAL:
60-
$this->_session_id = hexdec($u['h6'] . $u['h5']);
61-
$ret = substr($this->_data_recv, 8);
62-
break;
63-
case Util::COMMAND_TYPE_DATA:
64-
$ret = hexdec($u['h6'] . $u['h5']);
65-
break;
66-
default:
67-
$ret = false;
58+
$ret = false;
59+
$session = hexdec($u['h6'] . $u['h5']);
60+
61+
if ($type === Util::COMMAND_TYPE_GENERAL && $session_id === $session) {
62+
$ret = substr($this->_data_recv, 8);
63+
} else if ($type === Util::COMMAND_TYPE_DATA && !empty($session)) {
64+
$ret = $session;
6865
}
6966

7067
return $ret;

zklib/src/Attendance.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ public function get(ZKLib $self)
1717
$command = Util::CMD_ATT_LOG_RRQ;
1818
$command_string = '';
1919

20-
$session_id = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
21-
22-
if ($session_id === false) {
20+
$session = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
21+
if ($session === false) {
2322
return [];
2423
}
2524

26-
$self->_session_id = $session_id;
2725
$attData = Util::recData($self);
2826

2927
$attendance = [];

zklib/src/Connect.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public function connect(ZKLib $self)
3131
if (strlen($self->_data_recv) > 0) {
3232
$u = unpack('H2h1/H2h2/H2h3/H2h4/H2h5/H2h6', substr($self->_data_recv, 0, 8));
3333

34-
$self->_session_id = hexdec($u['h6'] . $u['h5']);
34+
$session = hexdec($u['h6'] . $u['h5']);
35+
if (empty($session)) {
36+
return false;
37+
}
38+
39+
$self->_session_id = $session;
3540
return Util::checkValid($self->_data_recv);
3641
} else {
3742
return false;
@@ -66,6 +71,7 @@ public function disconnect(ZKLib $self)
6671
try {
6772
@socket_recvfrom($self->_zkclient, $self->_data_recv, 1024, 0, $self->_ip, $self->_port);
6873

74+
$self->_session_id = 0;
6975
return Util::checkValid($self->_data_recv);
7076
} catch (ErrorException $e) {
7177
return false;

zklib/src/Fingerprint.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ public function _getFinger(ZKLib $self, $uid, $finger)
4646
'tpl' => ''
4747
];
4848

49-
$session_id = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
50-
51-
if ($session_id === false) {
49+
$session = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
50+
if ($session === false) {
5251
return $ret;
5352
}
5453

55-
$self->_session_id = $session_id;
5654
$data = Util::recData($self, 10, false);
5755

5856
if (!empty($data)) {

zklib/src/User.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ public function get(ZKLib $self)
5757
$command = Util::CMD_USER_TEMP_RRQ;
5858
$command_string = chr(Util::FCT_USER);
5959

60-
$session_id = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
61-
62-
if ($session_id === false) {
60+
$session = $self->_command($command, $command_string, Util::COMMAND_TYPE_DATA);
61+
if ($session === false) {
6362
return [];
6463
}
6564

66-
$self->_session_id = $session_id;
6765
$userData = Util::recData($self);
6866

6967
$users = [];

0 commit comments

Comments
 (0)