Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected String doInBackground(String... params) {
- String type = params[0];
- String login_url = "xxxx/login.php"; //URL to login script
- String register_url = "xxxx/hvzregister.php"; //URL to register script
- String update_url ="xxxx/update.php"; //URL to update script
- String team_url ="xxxx/teaminsert.php"; //URL to team script;
- URL url; //URL
- HttpURLConnection httpURLConnection; //Http connection with via URL
- OutputStream outputStream; //Stream for sending out data
- BufferedWriter bufferedWriter; //Writes out data
- String post_data; //The data to post
- InputStream inputStream; //Stream for receiving data
- BufferedReader bufferedReader; //Read data in
- String result = "";
- String line = "";
- if (type.equals("Login")) {
- try {
- String user_name = params[1];
- String password = params[2];
- url = new URL(login_url);
- httpURLConnection = (HttpURLConnection)url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- outputStream = httpURLConnection.getOutputStream();
- bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- post_data = URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8")+"&"
- +URLEncoder.encode("password", "UTF-8")+"="+URLEncoder.encode(password, "UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- inputStream = httpURLConnection.getInputStream();
- bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
- while ((line = bufferedReader.readLine()) != null) {
- result += line;
- }
- bufferedReader.close();
- inputStream.close();
- httpURLConnection.disconnect();
- return result;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else if (type.equals("register")) {
- try {
- String username = params[1];
- String password = params[2];
- String email = params[3];
- url = new URL(register_url);
- httpURLConnection = (HttpURLConnection)url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- outputStream = httpURLConnection.getOutputStream();
- bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- post_data = URLEncoder.encode("username", "UTF-8")+"="+URLEncoder.encode(username, "UTF-8")+"&"
- + URLEncoder.encode("password", "UTF-8")+"="+URLEncoder.encode(password, "UTF-8")+"&"
- + URLEncoder.encode("email", "UTF-8")+"="+URLEncoder.encode(email, "UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- inputStream = httpURLConnection.getInputStream();
- bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
- while ((line = bufferedReader.readLine()) != null) {
- result += line;
- }
- bufferedReader.close();
- inputStream.close();
- httpURLConnection.disconnect();
- return result;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else if(type.equals("update")) {
- try {
- String latitude = params[1];
- String longitude = params[2];
- url = new URL(update_url);
- httpURLConnection = (HttpURLConnection)url.openConnection();
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- outputStream = httpURLConnection.getOutputStream();
- bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- post_data = URLEncoder.encode("latitude", "UTF-8")+"="+URLEncoder.encode(latitude, "UTF-8")+"&"
- +URLEncoder.encode("longitude", "UTF-8")+"="+URLEncoder.encode(longitude, "UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- inputStream = httpURLConnection.getInputStream();
- bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
- while ((line = bufferedReader.readLine()) != null) {
- result += line;
- }
- bufferedReader.close();
- inputStream.close();
- httpURLConnection.disconnect();
- return result;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void onLocationChanged(Location location) {
- double longitude = location.getLongitude();
- double latitude = location.getLatitude();
- String str_latitude = Double.toString(latitude);
- String str_longitude = Double.toString(longitude);
- String str_un = AppConstraints.sharedPreference.getValue(getApplicationContext(), AppConstraints.USERNAME_PREF, AppConstraints.USERNAME_KEY);
- String type = "update";
- BackgroundWorker backgroundWorker = new BackgroundWorker(this);
- backgroundWorker.execute(type, str_un, str_latitude, str_longitude);
- }
- <?php
- require "conn.php";
- $username = $_GET["username"];
- $latitude = $_POST["latitude"];
- $longitude = $_POST["longitude"];
- $float_lat = floatval($latitude);
- $float_lon = floatval($longitude);
- $sql_update = "UPDATE player SET latitude = '$latitude', longitude =
- '$longitude' WHERE ((username) = '$username')";
- $result = mysql_query($conn, $sql_update);
- if ($result) {
- echo "Table updated";
- }
- else {
- echo "Error";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement