The use of Cookies

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
musicscore
Power Poster
Power Poster
Posts: 489
Joined: Wed Jan 25, 2006 11:53 am

The use of Cookies

Post by musicscore »

Hey There Again.

I'm building a module and I want that module to know when an user visited a page.
When he visited the page less then x hours ago, an php action is skipt.

So I was thinking of two solutions :
  • Using a cookie - Set a cookie with a date value and exparation periode and check the date value (this is the easy way)
  • Register the user in a database with ip-address and timestamp. (A lot of programming)
I was thinking about using the cookie methode but sometimes coockies are blocked by the browser of the user.

What do you think is the best way to check to time an user was visiting a page.
Please your advise.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1795
Joined: Wed Feb 25, 2009 4:25 am

Re: The use of Cookies

Post by DIGI3 »

Typically you'd use session variables for this. I don't have specific recommendations as I'm not a module developer, but hopefully that points you in the right direction.
Not getting the answer you need? CMSMS support options
musicscore
Power Poster
Power Poster
Posts: 489
Joined: Wed Jan 25, 2006 11:53 am

Re: The use of Cookies

Post by musicscore »

Thanks Digi3

Session variables only resist as long as the visitor keeps his browser open. When he closes his browser, start it again and opens the website again, the module will not know when that user/ip-address was here before. So I need to use Cookies or a database entry.

That is why I think Session Variables will not work.

(Ps. I am also not a developer (yet) but trying to make a nice module and learn, learn and learn)
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1795
Joined: Wed Feb 25, 2009 4:25 am

Re: The use of Cookies

Post by DIGI3 »

Cookies are probably best in that case then. If you follow guidelines for the target audience, and don't store any personal information, most people will consent. If they do not consent or have cookies disabled, they are generally aware they will lose some functionality.
Not getting the answer you need? CMSMS support options
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1970
Joined: Mon Jan 29, 2007 4:47 pm

Re: The use of Cookies

Post by Jo Morg »

musicscore wrote: Mon Jul 21, 2025 4:01 pm
Session variables only resist as long as the visitor keeps his browser open. When he closes his browser, start it again and opens the website again, the module will not know when that user/ip-address was here before. So I need to use Cookies or a database entry.

That is why I think Session Variables will not work.
That's not entirely correct...
geeksforgeeks.org wrote:What Are Sessions in PHP?

A session in PHP is a way of storing information (in variables) to be used across multiple pages. Sessions are stored on the server and can hold large amounts of data. A session is identified by a unique session ID, which is typically stored as a cookie on the client’s browser. When the session is started using session_start(), PHP automatically associates the session ID with the corresponding session data on the server.
So sessions are also dependent on cookies.
Also keep in mind that sessions, by using cookies, are also subject to the legal rules that apply to cookies, and which vary somewhat depending on the visitors' country of origin. To the best of my knowledge if a session doesn't store personal information, or any information that may allow tracking visitors across domains, there is no need to ask consent.

Given the above, I tend to favor the use of sessions, since in this case the data that is of any interest to the site (app/module/etc...) is always stored securely on the server if best practices are observed. Note that if a browser blocks cookies, even sessions are impossible to manage as we can gather from the quote above. And cookies, even encrypted, are stored locally on the browser side and can be hijacked. A session id can also be hijacked, but it's not as serious as having the full data at hand in the cookies, encrypted or not.

HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Developers Discussion”