SLIM FRAMEWORK - 404 PAGE NOT FOUND

Asked

Viewed 574 times

0

Hello, good morning.

I am trying to make a route using SLIM and I can normally access via URL and internally(via menu) the pages with SLIM configured, but when I login to the site, it does not send to the page that was requested. For example:

When I log in, I should send it to the Dashboard page, but that doesn’t happen. Go to the code below:

PHP:

if(isset($_POST['btnEnviar'])){
        $sql        = "SELECT id, login, senha, nome FROM usuario WHERE login = '$login' AND senha = '$senha'";
        $consulta   = $conexao->consulta($sql);
        $row        = $conexao->busca($consulta);
        $total      = $conexao->conta($consulta);

        if($total == 1){
            $_SESSION['login'] = $login;
            $_SESSION['senha'] = $senha;
            //echo "<script language= 'JavaScript'> location.href='/dashboard'; </script>";
            header("Location: /dashboard");
        }else{
            session_unset();
            session_destroy();
            echo $alerta1;
        }

        $conexao->desconectar();
    }

SLIM

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

$app->get(
    '/dashboard/',
    function () {
        require_once("dashboard.php");
    }
);

I have tried several 'solutions', but without success, like; call via POST instead of GET, change page name among some others.

URL of Login: http://127.0.0.1/edsa-moisesdesenvolvedorweb.com.br/admin/login (When accessing, it continues on this page, informed error 404)

URL you should access : http://127.0.0.1/edsa-moisesdesenvolvedorweb.com.br/admin/Dashboard

Thanks in advance for the help of the community!

  • which version of slim?

  • is the second version

3 answers

1


all right? Sorry for the delay. I managed to solve your problem, I created a repository with the changes https://github.com/gaoliveira21/stackoverflow-question , basically I deleted the folder from slim and installed via Composer, and created a virtual host in xampp. to do this just find the httpd-vhosts.conf file and add this code

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:\xampp\htdocs\moises\minhapagina" #diretorio raiz do projeto
    ServerName www.minhapagina.com.br #url do site em localhost
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
    <Directory "C:\xampp\htdocs\moises\minhapagina"> #diretorio raiz do projeto
        Require all granted

        RewriteEngine On

        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [QSA,L]
    </Directory>
</VirtualHost>

this file is usually in this directory C: xampp apache conf extra then just change the hosts file that in windows gets in C: Windows System32 drivers etc adding this code

127.0.0.1       www.minhapagina.com.br #a mesma url que esta em ServerName no arquivo httpd-vhosts.conf
  • Thank you very much Gabriel!!! I will test soon, but you would know explain to me, because it did not work with the installation of normal Slim.

  • Maybe some problem with the autoload of the class, but I believe the main problem was the issue of apache cofiguration, since slim needs a configuration. you can find more details in the documentation http://www.slimframework.com/docs/v3/start/web-servers.html. but I believe this was the problem

0

  • Thanks for the suggestion. I did this that you reported, but it didn’t work tmb. I removed up the Dashboard block from SLIM and returned the redirect to Dashboard.php, but without success. It continues to keep redirecting to .. admin/login instead of Dashboard

  • I do not know if there is any problem with the login block, I am not understand more

  • 1

    you have a repository on github with your project?

  • Hi, Grabriel, I can. https://github.com/MoisesFausto/minhapagina/tree/master/admin Just so you don’t get confused so you don’t waste time looking, the things I’m working on are these: admin/index.php . .. controller/controller.php

  • 1

    Okay, I’ll take a look as soon as I get home.

  • Show, thank you!

  • Hello Moses, I published another answer here since the solution I found ended up getting a little extensive, I hope it helps.

Show 2 more comments

-2

To be honest the code is not very good but try to make these changes

$app->get(
    '/login/',
    function () use ($app) {
        require_once("login.php");
    }
);
...
        if($total == 1){
            $_SESSION['login'] = $login;
            $_SESSION['senha'] = $senha;
            $app->response->redirect('/admin/dashboard');
...
  • Adir, how do you think you could improve the code ?

  • Pow, it didn’t work out :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.