How to use the Location function in object orientation

0

I'm trying to direct the user to the panel page, when he logs in to the home page, but directing gives the error below, but if I use javascript with the same path it works.

Using Location:

WhenIusethelineofcodebelowIgettheredirect,butIthinkit'smoreappropriatetouseLocation.

    
asked by anonymous 21.01.2018 / 22:39

1 answer

0

The url are not the same as the one mentioned in the question

Look at the lines below:

Header:

header("Location:/views/painel.php");

Html

echo "<meta http-equiv='refresh' content='0;URL=views/painel.php' />";

Note that in header you are adding a / (bar ) before the URL. When you add this bar at the beginning, it means the user will have to be redirected to <raiz-do-projeto>/views/painel.php

Without the slash, you inform that the user should be redirected to the current URL + address informed. Ex:

Imagine that you are in the site administration area: https://www.example.com/admin/

When you access with the bar at the beginning (as it is in the header ), you are informing the user to be redirected to https://www.example.com/views/painel.php

When you access without the bar at the beginning (as it is in html ), you are informing the user to be redirected to%

Another error in your code is https://www.example.com/admin/views/painel.php before echo .

When you write something with Location , echo etc (or even there are "hidden" characters before opening the print tag). <?php can not modify the PHP information.

    
21.01.2018 / 22:51