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条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统