PHP - Verify that the session (login) is active [closed]

-1

I need to send an email notification of abandonment of the product in the cart to the customer after X minutes that he left the site without buying.

Does anyone know of any simple and effective way to verify that the user's login session is still active on the site?

Example: list all active sessions of the site, if the Y session is not active, send the abandonment email of the product X minutes after the client leaves the site.

    
asked by anonymous 15.07.2016 / 15:28

1 answer

2

I needed to do this on a system that I developed, in case it was not a shopping cart but logic is the same.

  • The first thing you'll have to do is create a form of control to know when the user is no longer active on the site. In my case I have created the lastRegistro (TIMESTAMP) field in my User table.
  • On the client screen I used javascript to do an ajax pulling every 10 seconds, requesting a file on my server that updated the lastRecord date in the User table.
  • Create the Product Cart table the NotificationSent (boolean) field to control whether I've already sent notification to this cart.
  • Create a script that scans all the carts that the NotificationSubmitted field is false and the LastStatus field has been updated for more than X minutes. At this point the script sends the email and updates the field NotificationSubmitted to true.
  • Add the script to run X automatic in X minutes. In my case I use the crontab of linux (to learn more about crontab go to this link . In my case I used this way to run every 10 minutes:

    * / 10 * * * * php -q PATH_DO_SCRIPT $

  • 15.07.2016 / 16:08