Forums

automatically detecting new entry to my site

I would like to know how to detect in my app, without having a login screen, that the user closed the site and now is re-entering my site. I tried using session[] but that is unchanged upon exit/re-entry. The same did not work for global variables in my app

My app does not have a login screen, since it is open to the public, but I want to log usage by ip address.

Ip addresses are in the access log. (links to logs are available on the "Web" page on PythonAnywhere)

I do not understand the answer. I get the ip address from the request_header so why should I use the access.log file. Maybe I did not explain myself properly. My problem is not the ip address, but rather to know that the user re entered the site, so I can log the usage. And I want it to be such that it happens only once per entering to my app, so I will record only one login in my log file. To make it clear, if the user closes the browser and re-open and reenter to my app, each time it is a new log. But as long as it did not close the site, no more than one log should be registered.

You normally use cookies to track it.

But cookies do not change between exit and re-entry. That is the purpose of cookies - to keep information between sessions

If you want to base you "exxit/entry" on whether the browser has closed and opened, you will probably need to use javascript in some way. I don't know if javascript gets events based on the browser closing, but you may be able to use something like that. Otherwise, you may have to poll your site and, when the polling pauses for a time, that means that the browser was closed.

Idea to use a timer and log the usage every minute or so?

@stillhaveit If you ask about polling, here's an example.