Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys. I have just created an intranet in my online store and I'm new at programming so need some help. I'm developing a system that makes this possible: when a user registers, the database detects that they are already a customer who has bought previously and it makes their purchases appear on another page, in this case, in the section of their profile.

What I have tried:

I need some help since I don't know how to do it or how to link the php and Mysql code between the registration form and the existing user profile page since it is not a tool that prints the user's data on the same page but rather prints them in another, in the profile section.

Thank you very much in advance! :)
Posted
Updated 27-Jul-21 3:21am
Comments
Richard MacCutchan 27-Jul-21 8:00am    
When a user tries to register, you should check in the database to see if they are already registered.

1 solution

If what you mean is detecting when a non-registered user has purchased from the site before, this is where things like cookies[^] would be useful. If a customer purchases a product from your website you could store the IDs of the products in a cookie, and when they register you could check whether the cookie exists and pull in the relevant information.

An alternative to using cookies would be to use localStorage[^] which is an alternative method for storing data in the browser. Using this would require you to send the product information to the server during the sign-up process.

Just be aware that storing data in either of these methods is no guarantee that you'll be able to get the product purchase information. If the user chooses to use another browser, clear their browser data, buy or register in an incognito mode, or even sign up using a different device, then you won't have access to that information.

It could be suggested that you could require an email address during the shopping check-out process, and then link any purchased products to the account during sign up. However, this would be a bad idea, not only due to regulation restrictions[^], but a malicious actor could sign up an account and use someone else's email to access their purchase history.
 
Share this answer
 
Comments
Chris Copeland 27-Jul-21 9:49am    
Following up on this after some thought, if you also want to protect the user from malicious actors accessing the cookies or local storage to see their purchase history, you could also use a JWT token to make things secure. Upon checkout generate a JWT token and store the purchase information in the database against the token, and send the token back to the browser to be stored in a cookie or local storage.

Upon registration, accept the JWT token as part of the submit process, and then look-up whether any purchases were made. This is far more secure because the JWT token does not expose the purchase information directly, and are incredibly difficult to forge. Some JWT tokens also allow you to use a signing key to encrypt and decrypt the contents, so you can even store the purchase information within the token and omit the database component altogether.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900