Hi All,
Request your help on the below issue, the below does not work(redirect) , no errors are reported both in PHP side nor Slim , just a blank page is displayed.
Tried the below, No luck
return $response->withRedirect('login');
return $response->withRedirect($this->router->pathFor('login'));
return $response->withRedirect($this->router->pathFor('login'), 200);
return $response->withHeader('Location', 'login');
$uri = $request->getUri()->withPath($this->router->pathFor('login'));
return $response->withRedirect($uri);
$uri = $request->getUri()->withPath($this->router->pathFor('login'));
return $response->withRedirect($uri, 200);
index.html
<head>
<body>
<div class="col-md-9 ml-sm-auto col-lg-10 main">
{% block content %}{% endblock %}
</div>
</body>
</head>
page_login.html
{% extends "index.html" %}
{% block content%}
<p>Welcome to Login Page</p>
{% endblock %}
PHP Code
session_start();
define("ROOT_PATH", 'https://'.$_SERVER['HTTP_HOST'].'/');
$loginauthMiddleware = function($request, $response, $next) {
$route = $request->getAttribute('route');
if (empty($route)) { throw new \Slim\Exception\NotFoundException($request, $response); }
$routeName = $route->getName();
$groups = $route->getGroups();
$methods = $route->getMethods();
$arguments = $route->getArguments();
$publicRoutesArray = array('login', 'allow');
if(empty($_SESSION['user']) && (!in_array($routeName, $publicRoutesArray))) {
**$uri = $request->getUri()->withPath($this->router->pathFor('login'));**
** return $response->withRedirect($uri, 200);**
} else { $response = $next($request, $response); }
return $response;
};
$app->add(loginauthMiddleware);
$app->get('/login', function($request, $response) use($app) {
return $this->view->render($response, 'page_login.html');
})->setName('login');
$app->post('/login', function ($request, $response, $args) {
$user = $_POST['Username'];
$pass = $_POST['Password'];
$au = new authendication();
$result = $au->vaildateUser($user, $pass);
if($result == "Successful") {
$_SESSION['user'] = $user;
return $this->view->render($response, 'page_dashboard.html');
}
})->setName('login');
$app->get('/', function($request, $response) use($app) {
return $this->view->render($response, 'page_home.html');
})->setName('allow');
$app->get('/dashboard', function($request, $response, $args) use($app) {
return $this->view->render($response, 'page_serverlist.html');
})->setName('dashboard');