I’ve a problem when use this code in my page:
Code with expire session
<?php
session_start();
if(!isset($_SESSION['clientmacs']) ) {
header('Location: index.php');
} else {
if(time() - $_SESSION['timeLogin'] > 1800) {
header('Location: include/logout.php');
}
$userclient = $_SESSION['clientmacs'];
?>
<html>
HTML CODE
</html>
<?php
}
?>
But if I use this code the problem disappears and the page works normally:
Code without expire session
<?php
session_start();
if(!isset($_SESSION['clientmacs'])) {
header('Location: index.php');
} else {
$userclient = $_SESSION['client'];;
?>
<html>
HTML CODE
</html>
<?php
}
?>
Error in Google Chrome:
This webpage has a redirect loop
Http://localhost/mac/index.php The website has too many redirects. The incidence may be
resolved by deleting the cookies from this site or allowing third party cookies. If
that fails, the incidence may be related to a bug in the server configuration, not the
computer.
You need to reset the $_SESSION value for timeout ($_SESSION[‘timeLogin’]) when you execute redirection, otherwise when the client is back from redirect the value in session is the same and will be again redirected.
You could solve it with:
and
Maybe (depending on your logic) is better clear the entire session, and let it be reconfigured through the normal flow (
session_destroy()) when you perform redirect.