1

This is my start page

<?php
    require 'vendor/slim/slim/Slim/Slim.php';

    \Slim\Slim::registerAutoloader();

    $app = new \Slim\Slim();
    $app->get('/login', function () {
        include 'login.php';
    });
    $app->post('/login/login_authenticate', function () {
        include 'login_authenticate.php';
    });
    $app->post('/login/login_authenticate/dash', function () {
        include 'dashboard.php';
    });
    $app->run();
?>

This is my authentication page. The if condition is working fine, but the page is not redirecting. I ve checked the conditions .

<?php
    error_reporting(0);

    $app      = new \Slim\Slim();
    $body     = $app->request->getBody();
    $value    = json_encode($_POST);
    $json     = json_decode($value, true);
    $uname    = $json['username'];
    $psswrd   = $json['password']; 
    $host     = "localhost";
    $username = "root"; 
    $password = ""; 
    $db_name  = "resource"; 

    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("resource")or die("cannot select DB");
    $sql = "SELECT * FROM user_master WHERE User_Name='$uname' &&   `             Pass_word='$psswrd'";`
    $result_set = mysql_query($sql);
    while($row = mysql_fetch_array($result_set)) {         
        $db_username= $row['User_Name'] ;
        $db_password= $row['Pass_word'] ;
    }
    if ($db_username==$uname &&$db_password==$psswrd ) {        
        $app->redirect("login/login_authenticate/dash");
    } else {
        die("User name doesnt match");
    }
    $app->run();
?>

Please help me fix this. Thanks in advance.

Szabolcs Páll
  • 1,402
  • 6
  • 25
  • 31
DINESH KUMAR
  • 121
  • 1
  • 1
  • 12
  • $app = Slim\Slim::getInstance(); should fix it. You cannot create a new instance since you are already executing one and the redirect throws an internal HALT and it wont be executed on the old stack after you create a new one. – geggleto Dec 17 '15 at 14:08

1 Answers1

0

Let's take a look to your route definition:

$app->post('/login/login_authenticate', function () {
    include 'login_authenticate.php';
});

This is your redirect:

$app->redirect("login/login_authenticate/dash");

Your redirect is pointing to a route that expect the POST method, by the it will try to find the one that expect the GET method.

This should fix it:

$app->get('/login/login_authenticate', function () {
    include 'login_authenticate.php';
});

Interesting related stuff:

Community
  • 1
  • 1
Davide Pastore
  • 8,678
  • 10
  • 39
  • 53