This repository was archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsubmit.php
More file actions
40 lines (39 loc) · 1.49 KB
/
Copy pathsubmit.php
File metadata and controls
40 lines (39 loc) · 1.49 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
<?php
session_start();
include('config.php');
include('function.php');
$url = $_POST['url'];
$code = $_POST['code'];
if (empty($url) || empty($code)) {
exit('{"code":-1,"msg":"参数缺失","result":""}');
}
if ($_SESSION['vcode'] != md5($code . $VERIFICATION_KEY) && $IMAGE_VERIFICATION) {
exit('{"code":-2,"msg":"抱歉,人机验证失败","result":""}');
}
$_SESSION['vcode'] = "Kagamine Yes!";
if (!is_url($url)) {
exit('{"code":-3,"msg":"不是一个正确的链接","result":""}');
}
$pdo = pdoConnect();
$shortCode = GetRandStr($URL_SHORTENER_LENGHT);
$id = rand(100000000, 999999999);
if (databaseQuery($pdo, "code", $shortCode)['num'] != 0 || databaseQuery($pdo, "id", $id)['num'] != 0) {
exit('{"code":-3,"msg":"抱歉出现了一个致命错误,请重试!","result":""}');
}
$databaseQuery = databaseQuery($pdo, "url", $url);
if ($REWRITE) {
$rewriteStr = "";
} else {
$rewriteStr = "?c=";
}
if ($databaseQuery['num'] == 0) {
$stmt = $pdo->prepare("insert into url_data(id,url,code)values(?,?,?)");
$stmt->bindValue(1, $id);
$stmt->bindValue(2, $url);
$stmt->bindValue(3, $shortCode);
if ($stmt->execute()) {
exit('{"code":1,"msg":"success","result":"' . get_http_type() . $_SERVER['HTTP_HOST'] . '/' . $rewriteStr . $shortCode . '"}');
}
} else {
exit('{"code":1,"msg":"success","result":"' . get_http_type() . $_SERVER['HTTP_HOST'] . '/' . $rewriteStr . $databaseQuery['result'][0]['code'] . '"}');
}