Android的PHP服务器服务器、Android、PHP

2023-09-06 06:52:40 作者:只愿始如初见

我工作的Andr​​oid应用程序,将信息发送到一个PHP服务器。 Android的应用程序应首先登录,然后如果登录成功的开始发送数据 这是PHP页面(登录):

i working in Android app that send information to a php server. the Android app should login first then if the login successful start to send the data this is the php page (login):

<?php
$data = file_get_contents('php://input');
$json = json_decode($data);
$id=$json->{'im'};

$con = mysql_connect('localhost','root','1111');
mysql_select_db('root') or die(' ');
$sql = "SELECT name FROM chiled WHERE `im` LIKE $id ";

$query = mysql_query( $sql );

$a=mysql_fetch_row($query);
print(json_encode($a[0]));
$n=$json->{'name'};


mysql_close();
?>

PHP页面接收来自Android应用程序的ID,然后,如果它检查数据库,然后发送响应的Andr​​oid应用程序,根据接收到的响应,如果登录成功与否的应用程序将决定,如果登录成功,则启动发送数据。 你觉得最好的方式开始接受在PHP服务器中的数据(如果登录成功)?我可以把一个新的页面来接收(创建Android应用程序的新连接连接到另一个页面,然后开始发送数据)数据,或者我能做到这一点在同一个登录页面。

the php page receive the id from the android app then check if it in the DB then send response to the android app, according to the received response the app will decided if the login successful or not ,if the login successful then start send the data. what do you think the best way to start to receive the data in the php server(if the login successful )?can i put a new page to receive(create a new connection in android app that connect to another page then start to send the data) the data or i can do that in the same login page .

推荐答案

如果登录成功,然后就可以开始一个PHP会话存储会话和验证。大多数网站的作品在此FASION(如堆栈溢出)。

if the login is successful then you can start a php session that store the session and validation. Most websites works in this fasion (for example Stack Overflow).

在PHP中的会话在默认情况下是通过cookie的PHPSESSID。因此,如果登录正确的,那么你可以返回该cookie,并在本地(服务器端)的会话与用户关联的。

A session in php by default is passed through cookie PHPSESSID. So, if the login is correct then you can return the cookie and locally (server side) associate the session with the user.

此外,PHP允许创建和操纵一个会话cookie的。

Also, PHP allow to create and manipulate a session cookie-less.

唯一的细节是,你必须一个会话的IP,因为安全问题相关联。

The only detail is that you must associate a session with the ip because security issues.

因此​​,周期可以是:

So, the cycle can be:

安卓--user /密码 - >的login.php --- PHPSESSID - >机器人

android --user/password--> login.php ---phpsessid--> android

安卓--phpsessid - > content_page.php ---信息--->机器人

android --phpsessid --> content_page.php ---information--->android

如果您尚未登录(或会话已过期)

and if you are not logged (or the session has expired)

安卓--phpsessid - > content_page.php ---错误页面(你是不允许的)--->机器人

android --phpsessid --> content_page.php ---error page (you are not allowed)--->android

 
精彩推荐
图片推荐