save.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // LInE - Free Education, Private Data
  3. //
  4. // This PHP must be used if you intend to register in MySQL server the students interactions.
  5. // Adjust the names here and those in your MySQL server.
  6. //
  7. // The following files make reference to the table fields (must use the same names "line_id, line_name, ...")
  8. // @see js/globals.js
  9. // @see js/circleOne.js
  10. // @see js/squareOne.js
  11. // @see js/squareTwo.js
  12. // Change these values according to your database settings
  13. $servername = "localhost"; // INSERT MySQL server (e.g "line.ime.usp.br")
  14. $username = "put_username"; // INSERT MySQL user name
  15. $password = "put_password"; // INSERT MySQL password
  16. $dbname = "db_ifractions"; // INSERT database name (default="db_ifractions")
  17. $tablename = "ifractions"; // INSERT table name (default="ifractions")
  18. function remove_accents ($stripAccents) {
  19. // $stripAccents = preg_replace('/[^\x20-\x7E]/','', $stripAccents); // remove all special characters - if necessary, uncomment it
  20. return $stripAccents;
  21. }
  22. // Get some information about the client IP
  23. function clientIP () {
  24. if (getenv("HTTP_CLIENT_IP"))
  25. $ip = getenv("HTTP_CLIENT_IP");
  26. elseif (getenv("HTTP_X_FORWARDED_FOR"))
  27. $ip = getenv("HTTP_X_FORWARDED_FOR");
  28. elseif (getenv("REMOTE_ADDR"))
  29. $ip = getenv("REMOTE_ADDR");
  30. $strIP = $ip;
  31. $resp = gethostbyaddr($ip);
  32. if (isset($resp) && strlen($resp)>0) {
  33. $strIP .= "; " . $resp;
  34. }
  35. return $strIP;
  36. }
  37. // Create connection
  38. $conn = new mysqli($servername, $username, $password, $dbname);
  39. // Check connection
  40. if ($conn->connect_error) {
  41. die("Connection failed: " . $conn->connect_error);
  42. }
  43. $ip = clientIP();
  44. // /js/globals.js: data = line_ip=120.0.0.1&line_name=name&line_lang=pt_BR
  45. // /js/squareOne.js: data += &line_game=Square&line_mode=a&line_oper=Plus&line_leve=1&line_posi=1&line_resu=true&line_time=3&line_deta=numBlocks:3, valBlocks: 1,1,1, blockIndex: 2, floorIndex: 2;url=php/save.php
  46. $name = $_REQUEST["line_name"];
  47. $date = date("Y-m-d H:i:s");
  48. $lang = $_REQUEST["line_lang"];
  49. $game = $_REQUEST["line_game"];
  50. $mode = $_REQUEST["line_mode"];
  51. $oper = $_REQUEST["line_oper"];
  52. $leve = $_REQUEST["line_leve"];
  53. $posi = $_REQUEST["line_posi"];
  54. $resu = $_REQUEST["line_resu"];
  55. $time = $_REQUEST["line_time"];
  56. $deta = $_REQUEST["line_deta"];
  57. $nameUnchanged = $name; // /js/preMenu.js: playerName
  58. $name = remove_accents($name);
  59. if (is_object($lang))
  60. $lang = json_decode($lang);
  61. // Table 'ifractions': line_id line_hostip line_playername line_datetime line_lang line_game line_mode line_operator line_level line_mappos line_result line_time line_details
  62. $sql = "INSERT INTO $tablename
  63. (line_hostip, line_playername, line_datetime, line_lang, line_game, line_mode, line_operator, line_level, line_mappos, line_result, line_time, line_details)
  64. VALUES
  65. ('$ip', '$name', '$date', '$lang', '$game', '$mode', '$oper', $leve, $posi, '$resu', $time, '$deta')";
  66. // Register in database
  67. if ($conn->query($sql) === TRUE) {
  68. print "Saved.";
  69. $result = "OK";
  70. } else {
  71. print "Error: " . $sql . "<br>" . $conn->error;
  72. $result = "Error: " . $conn->error;
  73. }
  74. // DEBUG
  75. $date = date('Y_m_d_H_i_s');
  76. $fp = fopen('../temp/file_' . $date . ".txt", 'w');
  77. fwrite($fp, "name_unchanged=" . $nameUnchanged . ", name=" . $name . "\n" . $sql . "\nResultado: " . $result);
  78. fclose($fp);
  79. $conn->close();
  80. ?>