search

Home  >  Q&A  >  body text

php - Determine whether the user has permission to access

There is a problem: When querying data through url parameters, the data is generally queried through id
For example, if you want to query the details of an order, then the id is the id of the order details table

"http://localhost/index/order/detail/id/3.html"

So can I change this ID to query other people’s order details?
When I make order details, do I need to determine whether it is an order from this customer? Is it troublesome to judge every time?
Or use the order number to query?

仅有的幸福仅有的幸福2754 days ago775

reply all(8)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:03:46

    When an id is passed to the background, the database query does not only query the condition of id=id
    It will also bring many conditions, such as the uid of the user's login, or the user account stored in the session

    Of course you'd better make something to prevent SQL injection. If people access your SQL in the form of id=1";, your SQL will be very dangerous.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 13:03:46

    The problem of permissions should be judged by the backend. Logically speaking, the frontend should pass an order id to the server (you pass the url parameter here), and then the backend will look up the table and return the data to the frontend. Regarding the issue of permissions, the backend can first determine whether the user has the permission to call this interface after receiving the interface call information from the front end. If so (and the logical data is reasonable, etc.), the data will be returned. If not, it will directly return that there is no permission. Access is controlled in this way.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:03:46

    The real order is confusing. The request is not really the primary key field of the data table, so you have to change it yourself

    reply
    0
  • PHPz

    PHPz2017-05-16 13:03:46

    Viewing order details requires at least two parameters, the order id and the current user id. The backend should first determine whether it has received these two parameters correctly, then find the corresponding order information based on the order ID, and then match the current user ID with the order user ID in the order information. If they are inconsistent, it will prompt that they have no access rights.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:03:46

    1. The same ID cannot be used as the basis for order query, such as using uuid
    2. The order table contains the field of which customer the current order data is. Bring this condition when querying

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:03:46

    The relationship between user UID and order ID is &&.

    reply
    0
  • 黄舟

    黄舟2017-05-16 13:03:46

    When checking the order, it should be:

    select * from 订单表 where id="id" and uid="uid"; 

    reply
    0
  • PHPz

    PHPz2017-05-16 13:03:46

    1. First determine whether the user is logged in and obtain the session to determine;
    2. Determine whether the user has permission to access the order details based on the user ID.

    reply
    0
  • Cancelreply