Interaction between ios and phpmysql

Source: Internet
Author: User
Tags php mysql mysql login
I would like to ask whether ios and phpmysql can interact with each other, that is, after filling in the orders form on ios, it is possible to merge logs into mysql. Currently, it is possible to post data into mysql (postman) but now there is a problem in the next section. how can I enable users to log on to php mysql on ios? Yes, you only need to use SESSION,
I want ios and php mysql to interact with each other
That is, after filling in the orders form on ios, the orders can be added to mysql.
Currently, it is possible to import post into mysql (postman)
But now there is a problem in the next segment.
Is how to allow users to log on to ios
Can mysql of php be used? Is it enough to use SESSION?
What kind of API does ios need?

Reply content:

I want to ask,
I want ios and php mysql to interact with each other
That is, after filling in the orders form on ios, the orders can be added to mysql.
Currently, it is possible to import post into mysql (postman)
But now there is a problem in the next segment.
Is how to allow users to log on to ios
Can mysql of php be used? Is it enough to use SESSION?
What kind of API does ios need?

I have a question: postman is only a Chrome browser plug-in used to test the server API. How can we directly interact with MySQL?
For your questions, you need to change the logon process.
1. add the authorize table, field

Token User_id Expires_in Login_at
Xxxx1 Userid1 Timestamp1 Timestamp2
Xxxx2 Userid2 Timestamp3 Timestamp4

2. verify the account and password when logging on.AuthorizeThe table sets the user's token to expire, inserts a new record, and returnsToken
3. when the API is requested, the Token request is used. the server receives the token and checks whether the table authorize has the token. If yes, the server determines whether the Token has expired. if not, proceed to the next step, if the token does not exist or expires, return the HTTP401 status code.

Token after logon)

First of all, the interaction between ios and the background is implemented through APIs .. In addition, there is a certain business logic between the API and MYSQL ..
The problem you mentioned should be as follows:
1. log on to ios and upload account and password parameters through API POST
2. the backend PHP accepts parameters through POST and compares them with the data in the database for verification.
3. you can generate a session, store the session in the database, and return the session to the ios client.
4. the ios client packs sessions into API requests.
5. the php background accepts any request to check whether the session exists in the session table. if the request is valid or not, the request is invalid.

In addition, the expiration mechanism is not considered .. Simple process

The simplest way is to use the web session mechanism, and the existing php code changes are minimal or even unnecessary.
Think of the API used for iOS as an ajax request on a webpage. php returns json data to facilitate client parsing.

For example:
The current php login may be like this: the user submits the user name and password through the form on the web page, php queries the mysql authentication user information, if you can log on, sets the session and cookie, marking that the user has logged on, then php returns the redirect response (the previous page or homepage ).
For ajax login, json data is returned in the last step, for exampleReturn json_encode (['code' => '1', 'MSG '=>' login successful! ']);

The above is the simplest php + mysql login example. if you do not understand it, search for "php ajax login" first ". If you know what we are talking about, you don't have to learn about iOS. IOS uses the same APIs as Ajax.
The iOS client uses the HTTP client (AFNetworking recommended) to request a URL. php can return json data. The system has automatically processed cookies, sessions, and so on. The iOS client does not need to process them manually.

JSON returned by the Api is only convenient for client parsing. you can also return xml, text, html, and other similar data. you only need to negotiate with the client.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.