header using relative address and " .. / " does not work

Asked

Viewed 276 times

2

How do I header a page that is one level up, e.g.: I have the following directory tree, I want to header from validarLogin.php to welcomePage.php? I tried using a .. / to access the views folder and it didn’t work

controller
--- validarCadastro.php
--- validarLogin.php
views
--- index.php
--- welcomePage.php

Redirect code:

$string = http_build_query($consulta);
$url = 'Location:'.'../views/welcomePage.php?'.$string;
header($url);
  • Because you don’t take some form of (or create a way to get) the base url of your application. This would solve the problem.

  • how so? I am accessed by localhost, the full address is: localhost/PHP/Site/modules/users/views/welcomePage.php

  • Show us the redirect code so we can help

  • If used 'Location:'.'http://localhost/PHP/Site/modules/users/views/ewelcomePage.php?'.$string; works

  • What’s your structure like? where do you call this Location? Which file? goes through an index.php outside of these directories for redirection??

  • It does not pass an index, this redirection is located at the end of the login validation and is independent of the result (logged in or not)

Show 1 more comment

1 answer

1


If you are using real paths (ie if you are not using Apache URL rewriting) something like the following code could solve:

$linkAtual = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$string = http_build_query($consulta);
$url = 'Location: '.$linkAtual.'/../views/welcomePage.php?'.$string;
header($url);

Location is usually quite rigid, notice that you did not put space between the : of the word Location and the URL, may also be what’s getting in the way.

If it still doesn’t work, inform a little more: - You get some error, if so, then what error do you get? - Do you use any platform or PHP pure? - Is using sobre escrita of URLs in the .htaccess?

Let us know what worked for you.

Browser other questions tagged

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