I am trying to show recently viewed items in my site in php.For which i was thinking to make use of cookies,according to which i want to store what user is clicking in a db with cookie values the users have.Now I dont know how to generate cookies dynamically for one pc or device,when user clicks items on my site while navigating through....
Please guide me on how to put cookie values in a db along with product details in database,so that later when they come to my site they should get recently visited products on basis of the cookie values in my db..
Related
I am working on a website where user clicks on a add buttons to get information about that topic. Currently, when user clicks on any add button i store the data in a cookie. For example,
Let's say the Topics are A, B, C, D and so on.
I store them in a cookie like - A,B,X,P,Z. In other words as a comma separated list. What I want to do is backup the preferences on server in a database. This way if the user clears cookies sometime i still have the data backed up. Also, the user will be able to login on other devices with same preferences.
If I connect to the database on every user click, I will hit the concurrent maximum connections list probably. Is there some way to do it efficiently?
Is there some other option altogether? I am looking for something like feedly where user clicks on add button and the preferences are saved.
Here is the idea for keep track of a user in an online-shopping website:
1 - When a user comes in for the first time, I'll create a random hash and I'll send this hash through a cookie to the user and simultaneously I'll create a user with this hash in my Users table.
In that table I will store many users data like: (and I use mongodb by the way)
* User page visit
* User choose products (means user cart in my shopping cart)
* User last login
and ....
2- When the same user comes again (say a day later), he will send that cookie (hash id) and I'll search into my database for that id and retrieve any data I want (e.g shopping-cart info).
I think this works fine and is a good way track the user (Do you agree on this?)
Problem :
What if a user cleans his browser history?
How do sites like youtube save our data (favourites and .... ) and even if I clear my browser or use another ip they had my favorites ready for me without logging into my account?
youtube-like sites store each and every details about the user interactions. For showing your favorites, your likes and other things it saves the data on the server. Whenever the user logs in, the users data will be shown. If you want to implement this, then it is better to go for cloud computing to manage data efficiently.
On my OpenCart website, I'm trying to display the recently viewed items by the current user. The current user can be either logged in or logged out.
I don't see any table in my database that would keep track of such data. Does anybody know what would be the best option to go about this? Should I be creating cookies to do this?
If I am not wrong you are saying current user (may not be logged in) and his recent viewed product, Here you dont have user id so you can set Cookie for this instead of using database.
If you want to keep track of recent viewed product for particular user only, you can store it in database like opencart does for wishlist/add to cart list etc so that when ever user logs in the last viewed products appears.
//library/customer login() and logout()
Currently I'm working on a Magento module that allows customers to upload files against their order at the product page.
So what I thought was to have the files saved in a folder created with the session id as the folder name, until they submit their order. But then I ran in to an issue with this solution, which is, when a customer uploads a file as a guest and if they logged in after, or if they create a new account, the session ID get change, and no way of back tracking previous session data or id.
I looked at visitor ID and that doesn't work either. coz for a new customers/visitors don't have a visitor id, so thats out too.
Any suggestion?
You can track such instances with a cookie & the right expiry time. The following documentation helped me out a lot when working with cookies:
http://www.quirksmode.org/js/cookies.html
Visitor ID doesn't change after login. It changes after logout, which is perfectly normal. Also, all visitors have visitor ID, whether they new or not or logged in or not.
What I would like to do is essentially check whether or not a user has clicked a certain link on a page. The idea behind the functionality is that a user can click "Thanks!" on a post created on the website, but they can only submit one "Thanks!" per post.
I have no problem creating a simple click counter for the "Thanks!" button, and save the count to a database using PDO, but I am not sure how I can assign a click to the user who's session is active.Also, posts are constantly being added to the site, so I would need a system which would scale to more posts automatically.
Any guidance is appreciated, thanks!
Note: I know I have not put any example code, but I believe this is simple enough for a good programmer to grasp quickly.
EDIT
On further thought, the IP can not be used to distinguish users, as this website will be used by many people on the same IP.
Are the users logged in or anonymous? If they are logged in just save their user id in a session variable and upload it with their vote to a table in your database.
I do something similar using an Ajax request to a .php page that inserts a row with the session user ID and the vote.
If they are anonymous you can save their ip but that leads to problems with users who share the same ip address. Another (bad) option is to use cookies but users can obviously just clear their cookies and vote again.