Repository navigation
Expand file tree
/
Copy pathshorten.php
More file actions
108 lines (108 loc) · 3.85 KB
/
Copy pathshorten.php
File metadata and controls
108 lines (108 loc) · 3.85 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require_once "phpqrcode.php";
require_once 'config.php';
//10进制转62进制
function from10_to62($num) {
$to = 62;
$dict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$ret = '';
do {
$ret = $dict[bcmod($num, $to) ] . $ret;
$num = bcdiv($num, $to);
} while ($num > 0);
return $ret;
}
//10进制转58进制(不包含 0OlI 字符)
function from10_to58($num) {
$to = 58;
$dict = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$ret = '';
do {
$ret = $dict[bcmod($num, $to) ] . $ret;
$num = bcdiv($num, $to);
} while ($num > 0);
return $ret;
}
//10进制转56进制(不包含 01OolI 字符)
function from10_to56($num) {
$to = 56;
$dict = '23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$ret = '';
do {
$ret = $dict[bcmod($num, $to) ] . $ret;
$num = bcdiv($num, $to);
} while ($num > 0);
return $ret;
}
//10进制转零宽度空白不显字符
function from10_to_zerowidth($num) {
$to = 2;
$dict = array ('​','‌');
$ret = '';
do {
$ret = $dict[bcmod($num, $to) ] . $ret;
$num = bcdiv($num, $to);
} while ($num > 0);
return $ret;
}
//文本生成二维码base64字符串
function qrbase64($text) {
ob_start();
QRcode::png($text, false, L, 10, 1, false);
$image = ob_get_clean();
header('Content-Type: text/html');
$ret = base64_encode($image);
return $ret;
}
$url = $_POST['url'];
if (!preg_match("/^(http|https|itms-services):\/\/(.*?)$/i", $url)) {
echo '<h3 style="color:#FF0000;">Invalid url should start with http:// or https:// </h3>';
} elseif ($url == 'http://' || $url == 'https://' || $url == 'itms-services://') {
echo '<h3 style="color:#FF0000;">Invalid url</h3>';
} else {
try {
$db = new PDO("sqlite:$sqlitedb") or die("fail to connect db");
//重复记录判断
$i=0;
do {
$i++;
$id = rand(3364, 195112); //如有需要,此处应和config.php中相同
$sql = "SELECT COUNT(*) as count FROM main where id=$id;";
$id_count= $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
} while ( $id_count[0]['count']>0 && $i<10 );
}
catch(Exception $e) {
die($e);
}
try {
$stmt = $db->prepare("INSERT INTO main (id, url, shortened, count, ip, create_time, user_agent, referer) VALUES (:id, :url, :shorturl, :count, :ip, :createtime, :useragent, :referer);");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':url', $url);
$stmt->bindParam(':shorturl', $shorturl);
$stmt->bindParam(':count', $count);
$stmt->bindParam(':ip', $ip);
$stmt->bindParam(':createtime', $createtime);
$stmt->bindParam(':useragent', $useragent);
$stmt->bindParam(':referer', $referer);
$zeroid = from10_to_zerowidth($id);
$shorturl = from10_to58($id);
$count = '0';
$createtime = date("Y-m-d H:i:s");
$useragent = $_SERVER['HTTP_USER_AGENT'];
$referer = $_SERVER['HTTP_REFERER'];
$stmt->execute();
}
catch(Exception $e) {
die($e);
}
echo '<h3 style="color:#bdbdbd;">Zero Width url:  <a id="zerourl" style="color:#000000;text-decoration:none;" href="' . "$domain/$zeroid" . '/" target="_blank">' . "$domain/$zeroid" . '/</a></h3>';
echo '<h3 style="color:#bdbdbd;">Short url:  <a id="shorturl" style="color:#000000;text-decoration:none;" href="' . "$domain/$shorturl" . '" target="_blank">' . "$domain/$shorturl" . '</a></h3>';
echo '
<h3><img src="data:image/png;base64,'.qrbase64($domain.'/'.$shorturl).'"></h3>';
echo '
<h3 style="color:#bdbdbd;">Your url is:  <a style="color:#000000;text-decoration:none;" href="' . $url . '" target="_blank">' . $url . '</a></h3>';
echo '
<h3><img src="data:image/png;base64,'.qrbase64($url).'"></h3>';
$db = null;
}
?>