Localhost перенаправлял вас слишком много раз. PHP
// On index.php
<?php
session_start();
include '../pages/YOURPHPFILE.php';
if(!isset($_SESSION['username'])){header("location: login.php");}
?>
// If you're using another file add this
<?php
session_start();
include '../pages/YOURPHPFILE.php';
if(isset($_SESSION['username'])){header("location: index.php");}
?>
Victorious Vole