PHP - Check that the session (login) is active

Asked

Viewed 1,152 times

-1

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

Does anyone know any simple and effective way to check if the user login session is still active on the site?

Example: list all active sessions of the site, if session Y is not active, send the product drop-out email X minutes after the customer leaves the site.

  • In PHP you can set the session expiration time, plus you can also check if you still have a session_id(). and whether the created session is still active: if ($_SESSION['status_sessao'] == 1) { // faz algo } else { //logoff }. See the php.net to understand how the session works. Start here.

  • Ivan, only I won’t have access to the user’s session. That way, what you said wouldn’t work the way I want it to.

  • What do you mean you won’t have access to the session? It’s the system that controls the session. I’m sorry, but I don’t think you’ve read the PHP documentation. There are other ways to do this, using javascript. But you need to understand how sessions work. Otherwise, I won’t be able to help you.

  • This will all be dynamic. My idea is to make a script that checks whether the user session that abandoned the product in the cart is active or not. If it is active, send an email to him about the product.

  • And what’s the difficulty in that? I don’t get it. "Do something" would be shooting. You can identify when someone abandoned the cart, you can’t consider the guy’s session. You have to consider when the purchase is not made within a certain time frame. It has nothing to do with session time.

  • Read Berriel’s comment in this post: http://answall.com/questions/115965/howto checkse-uma-sess%C3%A3o-Session-existe-ou-est%C3%A1-active-in-php This is what I was looking for.

  • You can compare the date the trolley was created, and check if an order was generated on the same date as the trolley. If it was not, you send an email, using crontab to remind the user that he did not give "buy". Scheduling the shooting at the end of the day, for him to receive the message early in the morning. Much simpler and effective.

  • If the guy dislodges, and reloads, he’ll be getting messages...

  • I think that the use of sessions to keep checking what I want will become too complex for something, theoretically, simple. I will only use the data I already have, which is the date the product was added to the cart. If it passes X minutes that was added and the purchase was not finalized, I send the email. To do these checks I will use a script with crontab every Y minutes, I think it is better this way and less complicated.

Show 4 more comments

1 answer

2

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

  1. The first thing you will 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 created in my User table the field last registration(TIMESTAMP).
  2. On the client screen I used javascript to make an ajax Pulling of 10 in 10 seconds, requesting a file on my server that updated the date of last registration in the User table.
  3. Create in the table of Product Cart the field notify(Boolean), to control if I’ve sent notification to that cart.
  4. Create a script that scans all the carts that field notify is false and the field last registration has been updated more than X minutes. At this point the script sends the email and updates the field notify for true.
  5. Add the script to run X automatically in X minutes. In my case I use the crontab linux (to learn more about crontab go to that link. In my case I used this way to rotate every 10 minutes:

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

  • I will do something similar to this, but using only the date when the product was added to the cart! Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.