Home Backend Development PHP Tutorial 第一次做网站,关于网站构造方面想请问上

第一次做网站,关于网站构造方面想请问上

Jun 13, 2016 am 11:16 AM
json nbsp session user

第一次做网站,关于网站构造方面想请教下

本帖最后由 xlrtx 于 2013-03-11 20:23:40 编辑
长短不一的字符串(可能为空字符串)保存到数据库里面还是保存成文本文件?
我做的是一个在线购物的网站,每个用户都会有个购物车

购物车(cart)里面保存了他们放进去的物品和物品的配置,

这个购物车(cart)储存的数据结构就是一个array(我保存成了json格式)

但是由于有的用户有放东西有的没有放,所以每个用户的购物车数据长度都不一样

请问购物车的内容(Json数据)我要保存到数据库里还是保持成文件?

如果保存成数据库, 我是放在user.cart里面 还是放到cart.items里面?

1)如果放到cart.items里,系统会等到用户添加物品到Cart里面后,再添加数据到cart,并且把用户的user.cart_id赋值为cart.id

当用户吧cart.item清空,则user.cart_id=0,并且删除对应的cartrow

2)如果保存到user.cart里面,每个user都会分配个很长的cart用来做存储,不知道会不会浪费资源?(我不清楚数据库的保存格式..)

3)如果保存成文件,我会在每个用户注册成功后生成一个$userid.json,放到一个私有文件夹里面,只有服务器可以访问,里面的内容可能是空.
数据库 json
------解决方案--------------------
一般网站的购物车,是通过保存session或者cookie的。
因为这样性能稍微好一点。
------解决方案--------------------
1、将 session 从默认的文件方式改换成数据库方式
2、直接操纵 $_SESSION,无需 json
3、为满足“注册的用户需要能够访问上次登录时的购物车”可在 session 表中增加一个用户名(用户id)字段,并适当调整 session 回调函数

于是:
如果考虑用数据库保存未结账信息,则 session 表已经做了。不必再做
如果考虑用文件保存未结账信息,则因为访问量巨大,多层目录文件管理困难;单层太慢。非万不得已,不与采纳
------解决方案--------------------
不要为了程序而写程序,那是为了提高自身水平才做的事

做实际工作时,没有搞清业务流程就考虑技术流程是错误的
我只说说你想法中的几点错误
1.没搞清为什么要保留购物车数据,只是为了保留而保留
其实大部分人已经接受了重新登录/掉线购物车清空的事实,因为这点而投诉的客户几乎没有

2.“如果有人获得了用户的帐号密码……”,帐号密码远比购物车数据重要得多,本末倒置了
如果我丢失了账户密码,我不担心别人看到购物车里面放的是避孕套还是笔墨纸砚,而是担心别人看到我的送货地址和收货人资料

3.问题必须都在程序解决
应该在业务逻辑解决的事情,却由技术逻辑扛下来,是绝对的不会做生意(做事)的表现

购物车数据属于临时数据,完成一次购物(重新选择也算完成),数据就没用了——或者说转换为订单数据
现在最大的区别只是时间,就是这个“完成过程”所耗费的时间和多次浏览的问题,顺便问一下,购物车里面的数据放几个月还有用么?
有些时候在技术有限的情况不应把问题想得复杂化,能做才做,不能做就如实反馈给业务逻辑层解决


非要转牛角尖的话,我再给你出一个业务逻辑方面的难题:
我和我的家人(可能不少于3人)共用一个购物帐号密码,同时在多点登录,购物并发货到不同地点或相同地点(订单不同),技术层面怎么解决?说明:拒绝二次登录属于业务层面逻辑而不是技术层面逻辑,我的意思是允许多点登录怎么做?

还是花点时间做好需求分析吧,和业务部门沟通最重要
------解决方案--------------------
好多大牛。

我也要做类似的网站。

mark了以后看。

还在学习《PHP和MySQL Web开发》这本书,看了一半了。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Combination of golang WebSocket and JSON: realizing data transmission and parsing Combination of golang WebSocket and JSON: realizing data transmission and parsing Dec 17, 2023 pm 03:06 PM

The combination of golangWebSocket and JSON: realizing data transmission and parsing In modern Web development, real-time data transmission is becoming more and more important. WebSocket is a protocol used to achieve two-way communication. Unlike the traditional HTTP request-response model, WebSocket allows the server to actively push data to the client. JSON (JavaScriptObjectNotation) is a lightweight format for data exchange that is concise and easy to read.

How to solve session failure How to solve session failure Oct 18, 2023 pm 05:19 PM

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

What is the difference between MySQL5.7 and MySQL8.0? What is the difference between MySQL5.7 and MySQL8.0? Feb 19, 2024 am 11:21 AM

MySQL5.7 and MySQL8.0 are two different MySQL database versions. There are some main differences between them: Performance improvements: MySQL8.0 has some performance improvements compared to MySQL5.7. These include better query optimizers, more efficient query execution plan generation, better indexing algorithms and parallel queries, etc. These improvements can improve query performance and overall system performance. JSON support: MySQL 8.0 introduces native support for JSON data type, including storage, query and indexing of JSON data. This makes processing and manipulating JSON data in MySQL more convenient and efficient. Transaction features: MySQL8.0 introduces some new transaction features, such as atomic

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Nov 18, 2023 pm 01:59 PM

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string. When writing programs in Golang, we often need to convert the structure into a JSON string. In this process, the json.MarshalIndent function can help us. Implement formatted output. Below we will explain in detail how to use this function and provide specific code examples. First, let's create a structure containing some data. The following is an indication

Pandas usage tutorial: Quick start for reading JSON files Pandas usage tutorial: Quick start for reading JSON files Jan 13, 2024 am 10:15 AM

Quick Start: Pandas method of reading JSON files, specific code examples are required Introduction: In the field of data analysis and data science, Pandas is one of the important Python libraries. It provides rich functions and flexible data structures, and can easily process and analyze various data. In practical applications, we often encounter situations where we need to read JSON files. This article will introduce how to use Pandas to read JSON files, and attach specific code examples. 1. Installation of Pandas

See all articles