Is this a good approach to create countdown timer like this?

Posted 4 months ago by behnampmdg3

Hi;

How would you tackle this issue:

Requirements:

When a visitor hits the page, load a countdown timer that shows X days, hours and minutes before expiring. When the visitor returns, the timer should be set from the time visitor first visited the page.

My solution:

Give a piece of Javascript code to the client to embed in the page. Each time that code gets loaded, I create a record with IP address of the visitor in the database.

When that page gets reloaded, I query the database, if the IP exists, instead of creating the record, I load the countdown timer associated with that id, calculate the time since created, and load the countdown accordingly.

Ideas?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.