CodeIgniter Forums

Full Version: Get last 2 access urls
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to get the last 2 urls a user access ?
PHP Code:

This will return the URL that you just came from, you can then save it to an array etc;
I found 1 way by using cookies .. not sure if that is the correct way ...
Hi Grigore,

Yes, to store the last TWO urls you will need to use some kind of persistent storage mechanism. This could be cookies, or something else like in a database, or in "sessions" (which can be either cookie or database driven).

Keep in mind, anything in a cookie is pretty easy for someone else to sniff, so if your URLs contain sensitive information (which they shouldn't), such as a secret login code for example, then you are opening yourself up to a security risk.
If you have a user who is logged in, you simple can track the urls he access and log it with a timestamp (table, logfile, ..).
If you have no login you do the same but theefore you have no personal data and of courese all anonymous users will be mixded together.
store it in session, and it will be fine Smile
(12-18-2014, 05:39 PM)libreteam_studio Wrote: [ -> ]store it in session, and it will be fine Smile

I agree with the rest. Store it in session and you will easily retrieve the last two urls.