Skip to content
Advertisement

how do I display “how many days ago a user visited a website” in PHP

I want to display how many days/hours/minutes/seconds ago a user last visited the website. I’m new to cookies and can’t get to make them work.

Edit: Right now $lastVisit and $thisVisit are the same, how would i make them separate?

Here’s my code so far (I know it’s doing nothing close to what it’s supposed to do):

JavaScript

Here’s the exercise I’m trying to do incase my explaination wasn’t clear: 1

Advertisement

Answer

You have this condition:

JavaScript

As a prerequisite to this line of code:

JavaScript

… so you only ever update an existing cookie. You never set a new one if this is the first visit.

You need to calculate $lastVisit if the cookie is set, but set the new cookie regardless (outside of the condition).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement