سؤال

I am a newbie and I am creating a form in which there are 10 buttons next to some products. When the user clicks on these buttons then the corresponding product name is added to an array in jquery. When the user submits the form, i pass that array to the server through ajax and then create a session for those values there. All this is working fine.

QUESTION:-

Is it dangerous to store the data at client side like this?
Can any malicious user play with that array of data and change it at client side?
Since I cant create a session on every click because it will need to connect to the server again and again, so what could be the best approach to do this?

هل كانت مفيدة؟

المحلول

Is it dangerous to store the data at client side like this?

Not if you do proper data validation server-side

Can any malicious user play with that array of data and change it at client side?

Yes

Since I cant create a session on every click because it will need to connect to the server again and again, so what could be the best approach to do this?

This would be a working option. Or you just submit the form instead of tryin to store everything in an array. Forms were developed to submit used data. Another option would be to use ajax to set the selcted choice onSelect()

نصائح أخرى

Is it like a shopping cart? wherein your are posting all the selected products to the server?

If so storing the just the product names on the client side is of no harm, definitely one can tamper the array, however on the server side you should validate the array with checks like it contains valid products etc, other than that there is no harm in it.

However one should avoid storing sensitive data on the client side, however in you case no issues.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top