Header cannot find past destination

Asked

Viewed 151 times

4

I’m working on a project and function header cannot locate the destination passed to it. I have the following folder structure:

inserir a descrição da imagem aqui

On a certain form, I pass a action for:

<form method="post" action="index.php?pagina=../controller/controllerCategoria">

So far so good, but what I would like is that when I arrived in this file, I could return to a file inside the admin.

I was trying with the following header:

header('Location:http://localhost/tecmidiaCor/admin/index.php?pagina=criarPaginas');

In that case I wanted to go back to the file criarPaginas.php.

I didn’t point out PHP why in my index.php I have a script that always assigns the contents of the page variable.

  • There’s a gap between Location: and the rest of the URL. Also, as far as I know you cannot specify a query in the field Location. Otherwise, make sure the path exists. And if you want, you can remove the schema and the domain, leaving only the path itself.

  • the question of space is not, the rest I did not understand what you put

  • for example I put the full file address locally, even though it doesn’t work, header('Location: /Users/andremartins/Developer/workspaces/php/tecmidiaCor/admin/index.php');

  • 1

    First of all, take a look at how the HTTP protocol works, at least on Wikipedia. The physical path of the file doesn’t work. The server can only serve files that are in the same subtree as the DocumentRoot (in the case of Apache). Assuming your DocumentRoot be it /Users/andremartins/developer/workspaces/php/, you can test with Location: /tecmidiaCor/admin/index.php.

1 answer

1


Well I managed to solve, what apparently occurs is that my server of my application in the case APACHE he starts sending the response of request requested before actually arriving at the function Header() or sends a body in the application layer in this case using the protocol HTTP this usually occurs by functions echo print or spaces before my PHP tags -- <?php found a function in which case the ob_start It solves the problem by holding this content before its completion. In my code I solved as follows, whereas I am centralizing my application on `

<body> <?php
if (isset($_GET["pagina"])) {
    require ($_GET["pagina"] . ".php");
} else {
    echo "<h1>Bem vindo ao sistema</h1>";
}
?></body>

so bringing all the pages to the same top and footer, so there was a code HTML before starting this script I imagine that the same would be being sent before the function HEADER() properly said, in fact the ideal would be to test in reader of snifer as wireshark so I’m guessing this happened, in my case I put the following code before everything in my index.php <?php ob_start(); ?> and my HEADER that was in another directory I just put in the following way header("Location: index.php?pagina=criarPaginas") that redirects to another directory of my application, I thank everyone including @Vinícius Gobbo A. de Oliveira

Browser other questions tagged

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