save.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // ATENCAO ao
  3. // * nome da base de dados: db_ifractions
  4. // * nome da tabela dados : ifractions
  5. // assets/cn/save.php on line 23, referer: http://milanesa.ime.usp.br/ifractions1/
  6. /// @see js/circleOne.js
  7. /// @see js/squareOne.js
  8. /// @see js/squareTwo.js
  9. function remove_accents ($stripAccents) {
  10. /*
  11. $stripAccents = strtr($stripAccents,
  12. 'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ',
  13. 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
  14. $stripAccents = preg_replace('/[^\x20-\x7E]/','', $stripAccents);
  15. */
  16. return $stripAccents;
  17. }
  18. // Monta vetor [0,1] de dados da m<E1>quina cliente
  19. function ipMaquina0 () {
  20. if (getenv("HTTP_CLIENT_IP"))
  21. $ip = getenv("HTTP_CLIENT_IP");
  22. elseif (getenv("HTTP_X_FORWARDED_FOR"))
  23. $ip = getenv("HTTP_X_FORWARDED_FOR");
  24. elseif (getenv("REMOTE_ADDR"))
  25. $ip = getenv("REMOTE_ADDR");
  26. $resp[0] = $ip;
  27. $resp[1] = gethostbyaddr($ip);
  28. return $resp;
  29. }
  30. // Monta vetor [0,1] de dados da m<E1>quina cliente
  31. function ipMaquina () {
  32. if (getenv("HTTP_CLIENT_IP"))
  33. $ip = getenv("HTTP_CLIENT_IP");
  34. elseif (getenv("HTTP_X_FORWARDED_FOR"))
  35. $ip = getenv("HTTP_X_FORWARDED_FOR");
  36. elseif (getenv("REMOTE_ADDR"))
  37. $ip = getenv("REMOTE_ADDR");
  38. $strIP = $ip;
  39. $resp = gethostbyaddr($ip);
  40. if (isset($resp) && strlen($resp)>0) {
  41. $strIP .= "; " . $resp;
  42. }
  43. return $strIP;
  44. }
  45. $servername = "localhost";
  46. $username = "root"; // "jrustler_uscore";
  47. $password = "sawgeo"; //"12345";
  48. $dbname = "db_ifractions"; //"jrustler_fscore";
  49. // Create connection
  50. $conn = new mysqli($servername, $username, $password, $dbname);
  51. // Check connection
  52. if ($conn->connect_error) {
  53. die("Connection failed: " . $conn->connect_error);
  54. }
  55. // $ip = $_REQUEST["s_ip"];
  56. $ip = ipMaquina();
  57. /*
  58. $vet_ip = ipMaquina0();
  59. $ip = "";
  60. if (isset($vet_ip[0]) && strlen($vet_ip[0]>0))
  61. $ip = $vet_ip[0];
  62. if (isset($vet_ip[1]) && strlen($vet_ip[1]>0))
  63. if (strlen($ip)>0)
  64. $ip = $ip . " - " . $vet_ip[1];
  65. else
  66. $ip = $vet_ip[1];
  67. */
  68. $play = $_REQUEST["s_name"];
  69. $date = date("Y-m-d H:i:s");
  70. $lang = $_REQUEST["s_lang"];
  71. $game = $_REQUEST["s_game"];
  72. $mode = $_REQUEST["s_mode"];
  73. $oper = $_REQUEST["s_oper"];
  74. $leve = $_REQUEST["s_leve"];
  75. $posi = $_REQUEST["s_posi"];
  76. $resu = $_REQUEST["s_resu"];
  77. $time = $_REQUEST["s_time"];
  78. $deta = $_REQUEST["s_deta"];
  79. $play0 = $play; // /var/www/html/ifractions1/js/preMenu.js: insert_name
  80. $play = remove_accents($play); // /js/squareOne.js:vars=s_ip=143.107.45.11&s_name=&s_lang=pt&s_game=Square&s_mode=A&s_oper=Plus&s_leve=1&s_posi=1&s_resu=true&s_time=3&s_deta=numBlocks:3, valBlocks: 1,1,1, blockIndex: 2, floorIndex: 2; url=assets/cn/save.php
  81. if (is_object($lang))
  82. $lang = json_decode($lang);
  83. // Table 'ifractions': id s_hostip s_playername s_datetime s_lang s_game s_mode s_operator s_level s_mappos s_result s_time s_details
  84. $sql = "INSERT INTO ifractions
  85. (s_hostip, s_playername, s_datetime, s_lang, s_game, s_mode, s_operator, s_level, s_mappos, s_result, s_time, s_details)
  86. VALUES
  87. ('$ip', '$play', '$date', '$lang', '$game', '$mode', '$oper', $leve, $posi, '$resu', $time, '$deta')";
  88. // Register in database
  89. if ($conn->query($sql) === TRUE) {
  90. print "Gravado/Grabado";
  91. $result = "OK";
  92. } else {
  93. print "Error: " . $sql . "<br>" . $conn->error;
  94. $result = "Erro: " . $conn->error;
  95. }
  96. //DEBUG
  97. // js/menu.js : var menuState = { player_info = ... username ...}
  98. // welcome
  99. // index.php: game.state.add('name', nameState);
  100. $name = $_REQUEST["name"];
  101. $username = $_REQUEST["username"];
  102. $data = date('Y_m_d_H_i_s');
  103. $fp = fopen('../../temp/file_' . $data . ".txt", 'w');
  104. fwrite($fp, "nome=" . $play0 . ", name=" . $name . ", username=" . $username . "\n" . $sql . "\nResultado: " . $result);
  105. fclose($fp);
  106. $conn->close();
  107. ?>