Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
Redirecting to another page on error with Slim Framework

I want to redirect to a page (error.php, for example) depending on the info in a form in my website. I managed to log an error like this:

if ($date > $curdate) {
    return $response
        ->withStatus(406)
        ->withHeader('Content-Type', 'text/html')
        ->write('You can\'t select dates in the future!');
}

How can I do it so it sends you to a page with that error in particular instead of logging/requesting it in the network tab?

Right now I get this:

Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/{date2}
Request Method:POST
Status Code:406 Not Acceptable
Remote Address:192.168.0.80:80
Referrer Policy:no-referrer-when-downgrade

Which is almost working as intended. What I want to do is for it to send me to "http://raspberrypi/chartAPI/error/406" (for example), and display the contents in a file called 406.php (or error406.php, or error.php or whatever call it).

I managed to do something with this:

return $response->withRedirect("error.php");

But I get this:

Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/error.php
Request Method:GET
Status Code:405 Method Not Allowed

And slim throws this error:

Method not allowed. Must be one of: POST

Why is it removing {date2}? And why is it asking for a POST method?

This question is a continuation of this one, but due to how this website handles these "old" questions, mine got pushed down and regardless of how many edits I put, it doesn't get any attention anymore.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

When you are using withRedirect, use a Route URL not a file to browse

The Error is about using GET Method Where the Route needs POST

I think this is Because you use a file to redirect to,Then the method will be Only GET not POST or others like a browser

I don't Know Why you are using POST whenever you pass parameters in URL ?!

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda