dongle7553 2017-03-04 14:22
浏览 162
已采纳

如何从服务器识别用户以处理请求

I would like to know how to identify user from server when any request from app is done. Like if I have logged into the app and want to update my profile and send the request to server. How will the server identify the request is from particular user ? I am using PHP as server language and storing user session using Shared Preferences.

Any help would be helpful.

  • 写回答

2条回答 默认 最新

  • dongzhi6927 2017-03-04 14:28
    关注

    The easiest way to accomplish this outcome is to attach a unique identifier to the user(randomly generated) .Store this information along with the time,name and identifier of the user in the database. Also persist in the app, shared preference is alright. But consider using databases.A great one is realm for android. Then when any request is sent to the server send the name of user along with their identifier perform a query search with this information. Thus returning any info stored for this user.

    Make any sense? Well there are other sophisticated approaches that can be tailored to your needs. the concept of shared preferences is to store small transient information. using a database permits much safer control over your data and managed operations asynchronously,which will pay a big role later when traffic is encountered. Consider web tokens as well for communication. JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题