S
S
SergLee2018-09-20 12:33:55
PHP
SergLee, 2018-09-20 12:33:55

Redirect if cookie is "older" than 2 minutes?

Hello. There is a script:

if(empty($_COOKIE['entry_time']))
SetCookie('entry_time', time(), time() + 24 * 60 * 60);

// Через 24 часа
if($_COOKIE['entry_time'] + 24 * 60 * 60 < time())
{
header('Location: http://site.ru/');
}

How should this script change so that the redirect would be on the condition that the cookie is "older" than 2 minutes. When entering without cookies, there was no redirect.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Letyagin, 2018-09-20
@JorryGo

if(empty($_COOKIE['entry_time']))
SetCookie('entry_time', time(), time() + 2 * 60);

// Через 2 минуты
if(!empty($_COOKIE['entry_time']) and $_COOKIE['entry_time'] + 2 * 60 < time())
{
header('Location: http://site.ru/');
}

C
catrinblaidd, 2018-09-20
@catrinblaidd

if (empty($_COOKIE['entry_time'])) {
  SetCookie('entry_time', time(), time() + 24 * 60 * 60);
} else {
  if ((time() - $_COOKIE['entry_time']) >= 2 * 60) {
    header('Location: http://site.ru/');
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question