submit.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. header('content-type:application/json');
  3. session_start();
  4. include('../config.php');
  5. include('../includes/function.php');
  6. $confessor = htmlspecialchars($_POST['name']);
  7. $contact = intval(htmlspecialchars($_POST['contact']));
  8. $ta = htmlspecialchars($_POST['taName']);
  9. $image = htmlspecialchars($_POST['image']);
  10. $introduction = htmlspecialchars($_POST['introduceTA']);
  11. $content = htmlspecialchars($_POST['toTA']);
  12. $timestamp = intval(htmlspecialchars($_POST['timestamp']));
  13. if (empty($confessor) || empty($contact) || empty($ta) || empty($introduction) || empty($content)) {
  14. exit('{"code":-3,"msg":"表单未填写完整或存在错误!"}');
  15. }
  16. if ($_SESSION['vcode'] != md5($_POST['vCode'] . $VERIFICATION_KEY) && $IMAGE_VERIFICATION) {
  17. exit('{"code":-2,"msg":"抱歉,人机验证失败","result":""}');
  18. }
  19. if ($timestamp - time() > 60 || time() - $timestamp > 60) {
  20. exit('{"code":-5,"msg":"提交失败!请检查您的系统时间!"}');
  21. }
  22. $all = 'Kagamine Yes!' . strval($contact) . $confessor . $ta . $image . $introduction . $content . strval($timestamp);
  23. if (md5($all) != $_POST['key']) {
  24. exit('{"code":-5,"msg":"出现了一个未知错误!请联系管理员!"}');
  25. }
  26. try {
  27. $pdo = pdoConnect();
  28. $stmt = $pdo->prepare("insert into loveway_data(id,favorite,confessor,contact,time,to_who,introduction,content,image,comment)values(?,?,?,?,?,?,?,?,?,?)");
  29. $love_id = rand(100000000, 999999999);
  30. $stmt->bindValue(1, $love_id);
  31. $stmt->bindValue(2, 0);
  32. $stmt->bindValue(3, $confessor);
  33. $stmt->bindValue(4, $contact);
  34. $stmt->bindValue(5, date("Y-m-d H:i:s", time()));
  35. $stmt->bindValue(6, $ta);
  36. $stmt->bindValue(7, $introduction);
  37. $stmt->bindValue(8, $content);
  38. $stmt->bindValue(9, $image);
  39. $stmt->bindValue(10, "[]");
  40. if ($stmt->execute()) {
  41. exit('{"code":1,"id":"' . strval($love_id) . '","msg":"表白信息提交成功!"}');
  42. } else {
  43. exit('{"code":-2,"msg":"抱歉,出现了一个未知错误!请与管理员联系!"}');
  44. }
  45. } catch (PDOException $e) {
  46. exit('{"code":-1,"msg":"抱歉,出现了一个致命错误!请与管理员联系!"}');
  47. }