have a problem with Slim V2. The problem is that i can’t redirect to my dashboard page after login.
this is my index.php code:
<?
require_once 'vendor/autoload.php';
//Inizio le inclusioni necessarie
require("config/database.php");
require_once("vendor/dabble/dabble/src/Dabble/Database.php");
require_once("vendor/dabble/dabble/src/Dabble/Result.php");
session_name('GeCo');
session_start();
date_default_timezone_set("Europe/Rome");
$db = new Dabble\Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
global $db;
$app = new \Slim\Slim(array(
'templates.path' => './template',
'debug' => true
));
\Slim\Slim::registerAutoloader();
require 'app/GeCo.php';
$app->run();
?>
And this is GeCo.php markup:
<?php
require_once('classes/Login.php');
use login\Login;
$app->get('/', function () use ($app) {
$app->redirect('/dashboard');
});
$app->get('/login', function () use ($app) {
$page = 'login.php';
$app->render($page);
});
$app->get('/dashboard', function () use ($app) {
$page = 'dashboard.php';
$app->render($page);
})->name('dash');;
$app->post('/login', function () use ($app,$db) {
try {
$result=[];
$username = $_POST['username'];
$password = $_POST['password'];
$login = new Login($db);
$result = $login->checkLogin($username,$password);
}catch (\Exception $e) {
error_log(json_encode(print_r($e->getTrace(), 1)));
} finally {
if ($result) {
$_SESSION['loggedUser'] = $username;
$_SESSION['password']=md5($password);
$app->redirect('/dashboard');
} else {
header ( 'Content-Type: application/json' );
echo json_encode('No user found.');
exit();
}
}
});
And finally this is my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
The problem is that the instruction “$app->redirect(’/dashboard’);” doesn’t work…The browser still remain in login page but in Network inspector i see that the dashboard page is rendered and the route called! I’m getting really mad
I have also tried many methods with the “$ response” but I did not succeed.
please help me
Thanks