-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathindex.php
More file actions
76 lines (70 loc) · 2.32 KB
/
Copy pathindex.php
File metadata and controls
76 lines (70 loc) · 2.32 KB
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
<?php
session_start();
require_once('./db/Pdomysql.php');
$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR;
$PNG_WEB_DIR = 'temp/';
if (!file_exists($PNG_TEMP_DIR)){
mkdir($PNG_TEMP_DIR);
}
include dirname(__FILE__).DIRECTORY_SEPARATOR.'phpqrcode'.DIRECTORY_SEPARATOR.'qrlib.php';
$filename = $PNG_TEMP_DIR.'test.png';
// uuid 生成切勿拿到生产环境里使用,虽然重复几率小,30秒将重新更新下session,至于你保存到数据啥滴、都可以
$uuid = '';
if(isset($_SESSION['buildqr']) and isset($_SESSION['buildqr']['timestamp']) and (time() - $_SESSION['buildqr']['timestamp']) < 30) {
$uuid = $_SESSION['buildqr']['uuid'];
} else {
$uuid = uuid();
// write to db
$db = Pdomysql::getInstance();
$sql = 'insert into `qrlogin`(uname,token)value("","'.$uuid.'")';
$status = $db->execute($sql);
if($status) {
$_SESSION['buildqr'] = [
'uuid' => $uuid,
'timestamp' => time(),
];
}
}
$tokenURL = 'http://192.168.1.111/qrlogin/api.php?token='.$uuid;
$filename = $PNG_TEMP_DIR.'test'.md5($tokenURL.'|L|10').'.png';
$imgSRC = $PNG_WEB_DIR.basename($filename);
QRcode::png($tokenURL, $filename, 'L', '10', 2);
echo
<<<QR
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>swoole+websocket+redis</title>
<script type="text/javascript">
var token = "$uuid";
</script>
<script src="./js/jquery.min.js"></script>
<script src="./js/login.js"></script>
</head>
<body>
<div id="status"></div>
<img src="$imgSRC" />
</body>
</html>
QR;
function uuid($namespace = '') {
static $guid = '';
$uid = uniqid("", true);
$data = $namespace;
$data .= $_SERVER['REQUEST_TIME'];
$data .= $_SERVER['HTTP_USER_AGENT'];
$data .= $_SERVER['REMOTE_ADDR'];
$data .= $_SERVER['REMOTE_PORT'];
$hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));
$guid =
substr($hash, 0, 8) .
'-' .
substr($hash, 8, 4) .
'-' .
substr($hash, 12, 4) .
'-' .
substr($hash, 16, 4) .
'-' .
substr($hash, 20, 12);
return $guid;
}