Scenario: I have a to-do list that is generated with JavaScript using JSON that was encoded on the server side. I put the todo item id in the HTML id attribute. So the process goes like this:
- Server side code creates a todo array.
- Serialize array to JSON
- Loop through array of JSON objects and render the todo-list.
Now I have to edit a certain to-do item and update it. It is done like this:
- I filter my JSON object array by id by comparing the to-do id that came from the HTML id attribute value to get the object.
- I use AJAX to pass the object to the
INSERT.PHP
page. - In the
INSERT.PHP
page I deserializ the JSON so I can update it in the database.
Problem: Putting the to-do item id in the HTML id attribute will cause a flaw in the system because the user will have the capability to alter the to-do item id using the browsers developer console.
Question: Is there a safe way to do it? Am I just doing it wrong or is this a normal thing to do?