Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am trying to build a cart for a ecommerce website. i want to know how can i keep track for user who are not logged in.

What I have tried:

i tried using remote addr but it seems to be changing for user
Posted
Updated 13-Jun-17 5:39am

You can't trust IP addresses at all: not only can they change (as the user moves around on a mobile, or laptop, or when the router is reset), they are also shared by all users connected to a single router - so all employees at the same company would share the same IP address.

Instead, use cookies to store the tracking id or a shopping cart on the user device - that way it moves with the user, he doesn't lose it, and his purchases aren't shared with other users. There is loads of info complete with example code available via Google: cookies php[^]
 
Share this answer
 
Comments
Member 13240406 13-Jun-17 11:51am    
ok i got what u said can we access system private ip address by php.
Richard Deeming 13-Jun-17 12:00pm    
You can't access the private IP address at all. And it wouldn't make sense if you could - it's private precisely because it doesn't make sense outside of the local network.
OriginalGriff 13-Jun-17 12:04pm    
No, it doesn't propagate beyond the router, and even if you could, it would match millions of others: mine is currently 192.168.0.5 (but it may not be tomorrow) and yours is probably very, very similar!
Member 13240406 13-Jun-17 12:10pm    
thanx to all for your support !!!
Simple: you use cookies[^].
 
Share this answer
 
Comments
Member 13240406 13-Jun-17 11:40am    
cant they be edited by the user. is there any other way.
Richard Deeming 13-Jun-17 11:42am    
Yes they can, and no there isn't.
Member 13240406 13-Jun-17 11:54am    
can i give unlimited time limit to a cookie .pls also tell how can i do so
Richard Deeming 13-Jun-17 11:59am    
You can set an expiry date a long time in the future - say 10 years.

NB: At the moment, you probably don't want to set the expiry date to 2038 or later, due to the UNIX epoch bug.
Member 13240406 13-Jun-17 12:09pm    
thanx to all for ur support !!!

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