Friendly, easy, lightweight, self-hostable CAPTCHA service. https://captcheck.netsyms.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * This file contains global settings and utility functions.
  4. */
  5. ob_start(); // allow sending headers after content
  6. //
  7. // Unicode, solves almost all stupid encoding problems
  8. header('Content-Type: application/json; charset=utf-8');
  9. header('X-Content-Type-Options: nosniff');
  10. header('Access-Control-Allow-Origin: *');
  11. $session_length = (60 * 60) * 8; // 1 hour x 8 = 8 hours
  12. session_set_cookie_params($session_length, "/", null, false, true);
  13. session_start(); // stick some cookies in it
  14. // renew session cookie
  15. setcookie(session_name(), session_id(), time() + $session_length);
  16. // Composer
  17. require __DIR__ . '/vendor/autoload.php';
  18. require __DIR__ . '/settings.php';
  19. /**
  20. * Kill off the running process and spit out an error message
  21. * @param string $error error message
  22. * @param string $fault who's fault the error is: "server" (default) or "client".
  23. */
  24. function sendError($error, $fault = "server") {
  25. if ($fault == "server") {
  26. header('HTTP/1.1 500 Internal Server Error');
  27. $code = 500;
  28. } else {
  29. header('HTTP/1.1 400 Bad Request');
  30. $code = 400;
  31. }
  32. die(json_encode(["error" => $error, "code" => $code]));
  33. }
  34. // Database settings
  35. // Also inits database and stuff
  36. use Medoo\Medoo;
  37. $database;
  38. try {
  39. $database = new Medoo([
  40. 'database_type' => DB_TYPE,
  41. 'database_name' => DB_NAME,
  42. 'server' => DB_SERVER,
  43. 'username' => DB_USER,
  44. 'password' => DB_PASS,
  45. 'charset' => DB_CHARSET
  46. ]);
  47. } catch (Exception $ex) {
  48. sendError("Database error. Try again later.");
  49. }
  50. if (!DEBUG) {
  51. error_reporting(0);
  52. } else {
  53. error_reporting(E_ALL);
  54. ini_set('display_errors', 'On');
  55. }
  56. $VARS;
  57. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  58. $VARS = $_POST;
  59. define("GET", false);
  60. } else {
  61. $VARS = $_GET;
  62. define("GET", true);
  63. }
  64. /**
  65. * Checks if a string or whatever is empty.
  66. * @param $str The thingy to check
  67. * @return boolean True if it's empty or whatever.
  68. */
  69. function is_empty($str) {
  70. return (is_null($str) || !isset($str) || $str == '');
  71. }
  72. /**
  73. * Attempts to discover the user's IP address.
  74. * @return string IP string or "NOT FOUND".
  75. */
  76. function getUserIP() {
  77. $ip = "";
  78. if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
  79. $ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
  80. } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
  81. $ip = $_SERVER["HTTP_CLIENT_IP"];
  82. } else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
  83. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  84. } else if (isset($_SERVER["HTTP_X_FORWARDED"])) {
  85. $ip = $_SERVER["HTTP_X_FORWARDED"];
  86. } else if (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
  87. $ip = $_SERVER["HTTP_FORWARDED_FOR"];
  88. } else if (isset($_SERVER["HTTP_FORWARDED"])) {
  89. $ip = $_SERVER["HTTP_FORWARDED"];
  90. } else if (isset($_SERVER["REMOTE_ADDR"])) {
  91. $ip = $_SERVER["REMOTE_ADDR"];
  92. } else {
  93. $ip = "NOT FOUND";
  94. }
  95. return $ip;
  96. }