CodeIgniter Forums
Existing library/module: Code to track visitor's unique id in cookies? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Existing library/module: Code to track visitor's unique id in cookies? (/showthread.php?tid=16312)

Pages: 1 2


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]Fero[/eluser]
Hi, is there any library/helper/module, whatever that helps to track customers?

I'd need to get unique number to every visitor (shopping cart list memory). Is there something outthere to use straightaway? What I need is just unique ID of every visitor, check that it's him/her.. :-)


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]drewbee[/eluser]
First of all, you never use IP's to a track a user as they can change or easily be manipulated.

Second of all, take a look at the session class http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

Should be exactly what you are looking for.


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]Fero[/eluser]
but session class regenerates the session_id every 5 minutes. I need to keep that ID for the lifetime of the cookie OR with regeneration of the ID I'd need to update the DB - table containg the shopping cart of user.


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]drewbee[/eluser]
Why not store this shopping cart information in the session variables? Why are you trying to save them to the database if they are not permanently associated with a user?

Anyways, even though CI can generate a new session id, you could save an string to your session if you want to store actual temp cart details in a database.

- when user enters page, save to session $unique_id = md5(session_id + ip_address)
- when user enters item to cart, use $unique_id;

If CI regenerates session_id, it doesn't matter, because you are tracking the user in the DB by $unique_id, which will stay consistent in the session even if the session_id changes.

Does that make sense?


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]Fero[/eluser]
The idea of storing shopping cart in session didn't cross my mind, good one. thank you


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]drewbee[/eluser]
No problem. IMO makes it much easier to manage Smile You will now only have records in your DB of actual items that have been committed to being purchased, of which you can associate the records to an actual user account.


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]Tom Schlick[/eluser]
just a note to this. there is a nice cart library in the svn version of CI. if you wanna save yourself some hassle id take a look at it Smile


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]drewbee[/eluser]
Nice! Didn't know about that. It has some nice features that may be worth looking at.


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]Fero[/eluser]
erm, svn version? how do i get that?


Existing library/module: Code to track visitor's unique id in cookies? - El Forum - 03-03-2009

[eluser]drewbee[/eluser]
In the simplest form,

Go to Codeigniter > Downloads > visit the svn trunk and find system/libraries/cart.php for the plain text

http://dev.ellislab.com/svn/CodeIgniter/trunk/system/libraries/Cart.php


Or you could do a checkout if you have some type of svn setup.

Edit: Remember this is in the SVN, so their may still be some bugs associated with it. It hasn't been 'officially' released yet.