Advertisement
Guest User

Untitled

a guest
Mar 7th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. protected String doInBackground(String... params) {
  2. String type = params[0];
  3. String login_url = "xxxx/login.php"; //URL to login script
  4. String register_url = "xxxx/hvzregister.php"; //URL to register script
  5. String update_url ="xxxx/update.php"; //URL to update script
  6. String team_url ="xxxx/teaminsert.php"; //URL to team script;
  7. URL url; //URL
  8. HttpURLConnection httpURLConnection; //Http connection with via URL
  9. OutputStream outputStream; //Stream for sending out data
  10. BufferedWriter bufferedWriter; //Writes out data
  11. String post_data; //The data to post
  12. InputStream inputStream; //Stream for receiving data
  13. BufferedReader bufferedReader; //Read data in
  14. String result = "";
  15. String line = "";
  16. if (type.equals("Login")) {
  17. try {
  18. String user_name = params[1];
  19. String password = params[2];
  20. url = new URL(login_url);
  21. httpURLConnection = (HttpURLConnection)url.openConnection();
  22. httpURLConnection.setRequestMethod("POST");
  23. httpURLConnection.setDoOutput(true);
  24. httpURLConnection.setDoInput(true);
  25. outputStream = httpURLConnection.getOutputStream();
  26. bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
  27. post_data = URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8")+"&"
  28. +URLEncoder.encode("password", "UTF-8")+"="+URLEncoder.encode(password, "UTF-8");
  29. bufferedWriter.write(post_data);
  30. bufferedWriter.flush();
  31. bufferedWriter.close();
  32. outputStream.close();
  33. inputStream = httpURLConnection.getInputStream();
  34. bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
  35. while ((line = bufferedReader.readLine()) != null) {
  36. result += line;
  37. }
  38. bufferedReader.close();
  39. inputStream.close();
  40. httpURLConnection.disconnect();
  41. return result;
  42. } catch (MalformedURLException e) {
  43. e.printStackTrace();
  44. } catch (IOException e) {
  45. e.printStackTrace();
  46. }
  47. } else if (type.equals("register")) {
  48. try {
  49. String username = params[1];
  50. String password = params[2];
  51. String email = params[3];
  52. url = new URL(register_url);
  53. httpURLConnection = (HttpURLConnection)url.openConnection();
  54. httpURLConnection.setRequestMethod("POST");
  55. httpURLConnection.setDoOutput(true);
  56. httpURLConnection.setDoInput(true);
  57. outputStream = httpURLConnection.getOutputStream();
  58. bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
  59. post_data = URLEncoder.encode("username", "UTF-8")+"="+URLEncoder.encode(username, "UTF-8")+"&"
  60. + URLEncoder.encode("password", "UTF-8")+"="+URLEncoder.encode(password, "UTF-8")+"&"
  61. + URLEncoder.encode("email", "UTF-8")+"="+URLEncoder.encode(email, "UTF-8");
  62. bufferedWriter.write(post_data);
  63. bufferedWriter.flush();
  64. bufferedWriter.close();
  65. outputStream.close();
  66. inputStream = httpURLConnection.getInputStream();
  67. bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
  68. while ((line = bufferedReader.readLine()) != null) {
  69. result += line;
  70. }
  71. bufferedReader.close();
  72. inputStream.close();
  73. httpURLConnection.disconnect();
  74. return result;
  75. } catch (MalformedURLException e) {
  76. e.printStackTrace();
  77. } catch (IOException e) {
  78. e.printStackTrace();
  79. }
  80. } else if(type.equals("update")) {
  81. try {
  82. String latitude = params[1];
  83. String longitude = params[2];
  84. url = new URL(update_url);
  85. httpURLConnection = (HttpURLConnection)url.openConnection();
  86. httpURLConnection.setRequestMethod("POST");
  87. httpURLConnection.setDoOutput(true);
  88. httpURLConnection.setDoInput(true);
  89. outputStream = httpURLConnection.getOutputStream();
  90. bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
  91. post_data = URLEncoder.encode("latitude", "UTF-8")+"="+URLEncoder.encode(latitude, "UTF-8")+"&"
  92. +URLEncoder.encode("longitude", "UTF-8")+"="+URLEncoder.encode(longitude, "UTF-8");
  93. bufferedWriter.write(post_data);
  94. bufferedWriter.flush();
  95. bufferedWriter.close();
  96. outputStream.close();
  97. inputStream = httpURLConnection.getInputStream();
  98. bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
  99. while ((line = bufferedReader.readLine()) != null) {
  100. result += line;
  101. }
  102. bufferedReader.close();
  103. inputStream.close();
  104. httpURLConnection.disconnect();
  105. return result;
  106. } catch (MalformedURLException e) {
  107. e.printStackTrace();
  108. } catch (IOException e) {
  109. e.printStackTrace();
  110. }
  111. }
  112.  
  113. public void onLocationChanged(Location location) {
  114. double longitude = location.getLongitude();
  115. double latitude = location.getLatitude();
  116. String str_latitude = Double.toString(latitude);
  117. String str_longitude = Double.toString(longitude);
  118. String str_un = AppConstraints.sharedPreference.getValue(getApplicationContext(), AppConstraints.USERNAME_PREF, AppConstraints.USERNAME_KEY);
  119.  
  120. String type = "update";
  121. BackgroundWorker backgroundWorker = new BackgroundWorker(this);
  122. backgroundWorker.execute(type, str_un, str_latitude, str_longitude);
  123. }
  124.  
  125. <?php
  126. require "conn.php";
  127.  
  128. $username = $_GET["username"];
  129.  
  130. $latitude = $_POST["latitude"];
  131. $longitude = $_POST["longitude"];
  132.  
  133. $float_lat = floatval($latitude);
  134.  
  135. $float_lon = floatval($longitude);
  136.  
  137.  
  138.  
  139. $sql_update = "UPDATE player SET latitude = '$latitude', longitude =
  140. '$longitude' WHERE ((username) = '$username')";
  141.  
  142.  
  143. $result = mysql_query($conn, $sql_update);
  144.  
  145. if ($result) {
  146. echo "Table updated";
  147. }
  148. else {
  149. echo "Error";
  150. }
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement