使用 php 和 javascript 的购物车,无需数据库
我只是想问是否可以只用 php 和 javascript 创建一个购物车而不使用数据库?
我已经创建了一个,这有点不安全,因为在将产品添加到购物车时,我从标签中获取数据(名称和价格),因此如果有人将它们编辑为 0 成本,那么它只会以 0 成本将其添加到购物车。
那么,有没有其他方法可以安全地创建它,这样就没有人可以编辑它并以 0 成本获得完整的内容呢?
I just wanted to ask if it's possible to create a shopping cart with just php and javascript without using a database?
I've created one already, which is a bit unsecure because while adding the product to cart, I am fetching data (name and price) from labels so if someone edits them to cost 0, then it just adds it to cart on 0 cost.
So, is there any other way to create it with security, so that no one can edit it and get whole at cost 0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个奇怪的问题,但你的答案是否定的。您不可能拥有全客户端购物车并确保其安全。您需要使用 PHP 在服务器端验证所有用户提交的数据。对于任何做任何事情的网站来说,这都是良好、可靠的编程实践。
This is a strange question, but your answer is no. You can't have an all client-side shopping cart and make it secure. You will need to validate all user submitted data server-side using PHP. This is good, solid programming practice for any website doing anything.
如果您没有数据库来存储您的数据(例如价格客户端),那么这绝对是一个坏主意。如果您使用 PHP 数组而不是数据库,它应该可以工作,但可扩展性可能是一个问题。请记住,您仍然需要验证服务器端。您还需要在某处存储客户购买信息。如果没有数据库,您可以写入文件。但你确实应该使用数据库。您是否有某些原因不想使用数据库?
If what you men by no database is storing your data (eg. price client side) its definately a bad idea. If you use PHP arrays instead of a database it shuld work, but scalability might be an issue. Remember you still need to validate server side. Also you need to store customer purchase info somewhere. If theres no database, you could write to files. But you should really use a database. Is there some reason why you don't want to use a database?