For the first time I made a website, I would like to ask for a php Tutorial on website construction.

Source: Internet
Author: User
For the first time I made a website, I 'd like to ask about the website construction. Are strings of different lengths (which may be empty strings) stored in the database or saved as text files?
I am working on an online shopping website. every user has a shopping cart.

The shopping cart stores the configurations of the items they put in,

The data structure stored in this cart is an array (I saved it in json format)

However, because some users put things or not, the data length of each user's shopping cart is different.

Will the content of the shopping cart (Json data) be saved to the database or kept as a file?

If it is saved as a database, will it be stored in user. cart or cart. items?

1) if it is placed in cart. items, the system will wait until the user adds the item to Cart, then add the data to cart, and assign the user. cart_id to cart. id.

When the user cart. item is cleared, user. cart_id = 0 and the corresponding cartrow is deleted.

2) if it is saved to user. cart, each user will be allocated a long cart for storage. do you know if it will waste resources? (I do not know the database storage format ..)

3) if it is saved as a file, I will generate $ userid. json after each user registration is successful and put it in a private folder, which can only be accessed by the server and the content in it may be empty.


Reply to discussion (solution)

Generally, the shopping cart of a website stores session or cookie.
The performance is slightly better.

Generally, the shopping cart of a website stores session or cookie.
The performance is slightly better.

The user must be able to access the shopping cart of the last login ..

Unregistered users are written to the session.

1. change the session mode from the default file mode to the database mode.
2. directly manipulate $ _ SESSION without json
3. to meet the requirement of "a registered user needs to be able to access the shopping cart at last login", you can add a username (user ID) field in the session table and adjust the session callback function as appropriate.

So:
If you want to use the database to save the unpaid information, the session table has been done. No More
If you want to use files to save unchecked information, it is difficult to manage multi-level directory files because of the huge access volume. the single layer is too slow. It is not a last resort.

1. change the session mode from the default file mode to the database mode.
2. directly manipulate $ _ SESSION without json
3. to meet the requirement of "a registered user needs to be able to access the shopping cart at last login", you can add a username (user ID) field in the session table and adjust the session callback function as appropriate.

So:
If you want to use the database to save the unpaid information, the session table has been done. No More
If you want to save the file ......
I think this method is very troublesome.
If session is used, user A logs on to the website and saves the item to session1.
User A then changed the browser, logged on to the website, and created session2. However, session2 does not contain the content in session1.
Is sessionid required in the user table? Do I need to reset sessionN to session1?
In this case, the session is set to never expire.
If someone obtains the user's account password, they will know his session. if the password is changed, do they need to reset the session?
The session cannot expire because the cart information of the registered user cannot be lost.
However, the sessions of anonymous visitors need to be cleared after a certain period of time. how can this problem be solved ..



Json is used to make a dynamic shopping cart with ajax ..

A small website contains 7 to 8 pages.

I just want to know what is the regular solution to this problem?

It seems that the session is not suitable for saving the information of the registered user ..

This is not safe.

Do not write a program for the purpose of the program. it is done to improve its own level.

It is wrong to consider the technical process if the business process is not clear.
Let me just talk about some mistakes in your thoughts.
1. I don't know why I want to keep the shopping cart data, just to keep it
In fact, most people have accepted the fact that they have re-logged on/dropped the shopping cart and cleared it. because of this, almost no customers complained about it.

2. "If someone has obtained the user's account password ......", The account and password are far more important than the shopping cart data, and they put the cart upside down.
If I lose my account password, I don't worry if someone else sees a condom or ink in my shopping cart. Instead, I am worried that someone else will see my shipping address and recipient's information.

3. the problem must be solved in the program.
What should be solved in the business logic is carried down by the technical logic, which is definitely not a manifestation of doing business (doing things ).

The shopping cart data is temporary data. when a shopping is completed (the re-selection is complete), the data is useless ?? Or convert to order data.
The biggest difference now is time, which is the time spent in this "completion process" and the number of views. By the way, is it useful to store data in the shopping cart for a few months?
In some cases, when technology is limited, the problem should not be complicated and can only be done. if it cannot be done, the problem should be truthfully reported to the business logic layer for solution.


If you have to turn to the best, I will give you another business logic problem:
My family and I (probably not less than 3 people) share a shopping account password, log on at multiple points, shop and ship to different locations or the same location (different orders ), how to solve the problem at the technical level? Note: Rejecting secondary logon is a business logic rather than a technical logic. I mean, how can I allow multiple logins?

Please take some time to analyze your requirements. it is most important to communicate with the business department.

Do not write a program for the purpose of the program. it is done to improve its own level.

It is wrong to consider the technical process if the business process is not clear.
Let me just talk about some mistakes in your thoughts.
1. I don't know why I want to keep the shopping cart data, just to keep it
In fact, most people have accepted the fact that they have re-logged on/dropped the shopping cart and cleared it. because of this, almost no customers complained about it.

2. "If someone has obtained the user's account password ......", The account and password are much more important than the shopping cart data, and they put the cart upside down ......

Before adding an item to the shopping cart, the user needs to select the item configuration. if he takes the time to consider it, the session will expire.
He needs to re-add the item to his shopping cart. at this time, he finds that there are no items in his shopping cart. will he consider going to another online shop?

Second, you do not understand clearly. I mean:
If the shopping cart (session) needs to be permanently saved, if someone does not log out in a public place, other people can log on permanently even if they have changed their passwords, with the user's permissions, more information is obtained ..

And the question you gave is too outrageous .. It doesn't mean that technical solutions must be used to solve problems at the technical level.
An account is used to provide services to a person,
What is the significance of an account for multiple users ..

1. the database is used only when saving the shopping cart selection for the customer ?? Many websites have done this, because you didn't know how to study your peers. customers are responsible for the re-election if they don't save the record, and they are still browsing session/cookies continuously, it takes more than ten hours for him to operate cookies. I often use firefox. I picked products for ie online banking, or bought them the next day. I used to save the shopping cart in the middle.
2. it is his problem that the customer does not take his privacy seriously. I despise the person who threw away the package without tearing up the online shopping order. it is enough for the website to provide necessary warnings and user agreements. In addition, you do not know much about cookies. Generally, the data can be completely separated from the logon information. after logging on, resplice and load the general information.
3. the purpose of the problem I have given you is not to solve it with technology (it can also be solved, but to think about it when you are free), but to remind you of many actual situations, you can't solve this problem from the technical level by 100%. even if you solve this problem (account sharing is a common problem, this is the case in the community. mom doesn't know how to register, I can place orders with my account and pay for them). I can give you more questions. Therefore, we must standardize some processes at the business level to simplify things. Let's discuss with the business department. balancing the customer experience will not always be held by the problem. this is the solution to the problem.

Reference the reply from snmr_com on the 7th floor: Do not write a program for the sake of the program, it is done to improve its own level

It is wrong to consider the technical process if the business process is not clear.
Let me just talk about some mistakes in your thoughts.
1. I don't know why I want to keep the shopping cart data, just to keep it
In fact, most people have accepted the fact that they have re-logged on/dropped the shopping cart and cleared it. because of this, almost no customers complained about it.

2. "If someone has obtained the user's account password ......", Account ......

Let a few people upstairs talk about it as though I was a little tough ..
I have been writing c programs and do not like to waste memory .. For the first time, the school asked us to do this project, and php was just less than a week away ..

Because I don't know how database storage works.

So I just want to ask if I put the shopping cart information in the database, and each information is given a certain length, each user will have the shopping cart information (but some are long and short)
Will this waste space?

Storage in files will certainly not waste space, but will vchar be used for storage?

After talking about it for half a day, I just did my homework.

Database consumption is another problem

Storage space is not important, not all SSD is used, but the amount of information/traffic is important

For BS systems, the cost of a single problem is Pediatrics, but BS considers the cost of thousands of concurrent connections. Therefore, the most important thing is to do more important when necessary, that is, when a customer does not read a product, he only needs to load the product name to let him know what it is. he can read the database information of the product only when he wants to see the specific information of the product.

Database knowledge and other great guidance, my weaknesses

Well, in the course of industrial projects, the teacher found a few clients at random, and then gave the customer project to us ..

But what we do is a real website.

It also includes documentation, user manual, and presentations ..

No salary. we have to pay for it. the customer has to pay for it. OTZ.

Many Daniel.

I want to create a similar website.

Mark.

I am still reading the book PHP and MySQL Web development, and I have read it in half.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.