Selanjutnya, berikut script PHP untuk membaca log absensi dari mesin :
<?php set_time_limit(500); $IP = "192.168.5.98"; //isi dengan ip fingerprint $Key = "0"; // key di mesin fingerprint, nol adalah nilai default $Connect = fsockopen($IP, "80", $errno, $errstr, 1); if ($Connect) { $soap_request = "<GetAttLog> <ArgComKey xsi:type=\"xsd:integer\">".$Key."</ArgComKey> <Arg><PIN xsi:type=\"xsd:integer\">ALL</PIN></Arg> </GetAttLog>"; $newLine = "\r\n"; fputs($Connect, "POST /iWsService HTTP/1.0".$newLine); fputs($Connect, "Content-Type: text/xml".$newLine); fputs($Connect, "Content-Length: ".strlen($soap_request).$newLine.$newLine); fputs($Connect, $soap_request.$newLine); $buffer = ""; while($Response = fgets($Connect, 1024)) { $buffer = $buffer.$Response; } } else echo "Koneksi Gagal"; $buffer = Parse_Data($buffer,"<GetAttLogResponse>","</GetAttLogResponse>"); $buffer = explode("\r\n",$buffer); $c=0; for ($a=1; $a<count($buffer)-1; $a++) { $data=Parse_Data($buffer[$a],"<Row>","</Row>"); $export[$c]['pin'] = Parse_Data($data,"<PIN>","</PIN>");
$export[$c]['date'] = substr(Parse_Data($data,"<DateTime>","</DateTime>"),0,10) ; $export[$c]['time'] = substr(Parse_Data($data,"<DateTime>","</DateTime>"),11,8) ; $export[$c]['verif'] = Parse_Data($data,"<Verified>","</Verified>"); $export[$c]['state'] = Parse_Data($data,"<Status>","</Status>"); $export[$c]['wrkcode'] = Parse_Data($data,"<WorkCode>","</WorkCode>");
$c++;
} echo json_encode($export); function Parse_Data ($data,$p1,$p2) { $data = " ".$data; $hasil = ""; $awal = strpos($data,$p1); if ($awal != "") { $akhir = strpos(strstr($data,$p1),$p2); if ($akhir != ""){ $hasil=substr($data,$awal+strlen($p1),$akhir-strlen($p1)); } } return $hasil; } ?>
Hasil dari script diatas adalah log absensi dalam format JSON.