doupo1890 2013-11-13 20:07
浏览 42
已采纳

如何安全地将android位置数据发送到服务器

I've just started to get into Android development and am currently developing an app which part of the functionality is to update the GPS location hourly. I've managed to get the app to store the location in my database by posting the values to a php file similar to the one below. The problem I'm having trouble figuring out is how to do this securely so that only values from my android app are stored and not just any data that is posted to the url.

Simplified php file that receives gps values:

<?php 

require_once 'connect.php';

$imei = $_POST['imei'];
$longitude = $_POST['longitude'];
$latitude = $_POST['latitude'];

$result = mysqli_query($con, "UPDATE `device_location` SET `Longitude` = '$longitude', `Latitude` = '$latitude' WHERE `IMEI` = '$imei'"); 

?>

Essentially, anyone who knows the url of the php file and a valid IMEI number can post fake gps values. How can I verify that the gps values are only coming from my android app?

  • 写回答

2条回答 默认 最新

  • douzhao4071 2013-11-13 20:23
    关注
    1. You can use a string that is hardcoded in your app code in server and in android and don't share that with anyone.
    2. If you want to increment the security, you could create a string generated by yourself or by the any library that generate a GUID (token) in the server, so when the user autenticates in android app, save the string in the database with an expiration time (a column in the table and then verify that when the request is done, the token is valid). The token should be send in every request from the android app and when the user finish the session the token should be deleted , so when he authenticates again, get another token.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题