-
Notifications
You must be signed in to change notification settings - Fork 1
/
qrcodescanner.php
83 lines (70 loc) · 2.2 KB
/
qrcodescanner.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
82
83
<?php
if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}
$qrcode="OG4ELthJOb";
?>
<html>
<head>
<title>QR Code Scanner</title>
<link rel="stylesheet" href="/attendance/inc/bootstrap-3.3.7/dist/css/bootstrap.min.css" />
<script src="/attendance/inc/jquery-ui-1.12.1/external/jquery/jquery.js"></script>
<script src="/attendance/qrcode/jsqrcode-combined.js"></script>
<script src="/attendance/qrcode/html5-qrcode.js"></script>
<style>
.hidden {
display: none;
}
</style>
</head>
<body>
<div class="container" style="text-align: center">
<h1> QR Code scanner Example </h1>
<br><br>
<div id="qr" style="display: inline-block; width: 500px; height: 500px; border: 1px solid silver"></div>
<br><br>
<div class="row">
<button id="scan" class="btn btn-success btn-sm">start scaning</button>
<button id="stop" class="btn btn-warning btn-sm hidden">stop scanning</button>
</div>
<br><br>
<div class="row">
<div class="col-md-12">
<code>Start Scanning</code> <p id="result"></p> <span class="feedback"></span>
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function() {
$("#scan").on('click', function() {
$("code").html('scanning');
$('#qr').html5_qrcode(function(data){
// do something when code is read
$("#result").html('code scanned as: ' +data);
if(data === '<?=$qrcode?>'){
$("#result").addClass('alert alert-info');
}
},
function(error){
//show read errors
$(".feedback").html('Unable to scan the code! Error: ' +error)
}, function(videoError){
//the video stream could be opened
$(".feedback").html('Video error');
}
);
$("#scan").addClass('hidden');
$("#stop").removeClass('hidden');
});
$("#stop").on('click', function() {
$("#qr").html5_qrcode_stop();
$("code").html('Start Scanning');
$("#scan").removeClass('hidden');
$("#stop").addClass('hidden');
});
});
</script>