Krukosz
Krukosz

Reputation: 31

How to validate for data integrity between JS and PHP?

I am wondering about the right way of validating data on client and server side.

I have spreadsheet, made with JExcel addon, and I have to check if any user has changed headers. Spreadsheet data is generated using pivot function in database, so the column count and order would vary.

I locked all possibilities of headers editing by ordinary users, but if someone knows how to use console, it may be unlocked. The pivot is similar to the picture below:

enter image description here

The JExcel loads data from dynamic JSON generated by PHP script. I can calculate "checksum" for header order, but how to validate it when user will update spreadsheet? I have to validate if user sends spreadsheet based on the same pattern. How to do it in best way?

EDIT:

I created process logic:

  1. When the data is called by the user, php generates datahash and assigns it to the php session_id.
  2. Session_id is coded into md5 as well as datahash and all is saved to mysql database.
  3. The datahash is passed via http headers with ajax response (to deliver hash for the client-side verification)
  4. After the data is sent back, server reads all hashes generated within current php session.
  5. If any hash matches - data is valid. This solution is good, because I only need info if this data has been sent to user.

Upvotes: 0

Views: 287

Answers (1)

Paul
Paul

Reputation: 467

You can use some JWT to sign your data in the server-side.

Upvotes: 1

Related Questions