When logging in redirect to more than one page

Asked

Viewed 94 times

-3

For example, I am validating the login to redirect to the pages according to the access level:

if($_SESSION['usuarioNiveisAcessoId'] == "1"){
    header("Location: ./index.php/administrativo");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "2"){
    header("Location: ./index.php/colaborador");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "3"){
    header("Location: ./index.php/enfermagem");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "4"){
    header("Location: ./index.php/administradorlogistica");
}else{
    header("Location: ./index.php/cliente");
}

and works well.

Now intended was for the same level of access redirect to more than one page. I don’t know if it’s possible, I tried it this way for Session Level 4, but it doesn’t direct:

if($_SESSION['usuarioNiveisAcessoId'] == "1"){
    header("Location: ./index.php/administrativo");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "2"){
    header("Location: ./index.php/colaborador");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "3"){
    header("Location: ./index.php/enfermagem");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "4"){
    header("Location: ./index.php/administradorlogistica");
}else($_SESSION['usuarioNiveisAcessoId'] == "4"){
    header("Location: ./index.php/alertas3");
}

and also tried this:

if($_SESSION['usuarioNiveisAcessoId'] == "1"){
    header("Location: ./index.php/administrativo");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "2"){
    header("Location: ./index.php/colaborador");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "3"){
    header("Location: ./index.php/enfermagem");
}elseif($_SESSION['usuarioNiveisAcessoId'] == "4"){
    header("Location: ./index.php/administradorlogistica") AND header("Location: ./index.php/alertas3");
}else{
    header("Location: ./index.php/cliente");
}

But it didn’t work either.

  • 2

    Well, what you’re trying to do is kind of exotic. How do you expect the browser to show two things at the same time? open a new tab?

  • @Diego Martins does not intend on another tab, but he is right, it is not possible what I intend. I thought it, not to have to create

  • I know that in python with flask da to create general templates and modify them according to the level of access of the person or other user properties, flask and a framework, try to take a look at PHP frameworks to do this for you and save hours of code possibly

2 answers

0


header string $header [, bool $replace = TRUE [, int $http_response_code ]] ) : void
replace:
The optional replace Parameter indicates whether the header should replace a Previous similar header, or add a Second header of the same type. By default it will replace, but if you pass in FALSE as the Second argument you can force Multiple headers of the same type. For example:

According to the documentation:
The optional parameter replace indicates whether the header should replace a similar previous header or add a second header of the same type. By default it will be replaced, but if you pass FALSE as the second argument, you can force several headers of the same type.

In short: if you are trying to run 2 header(), to re-order to different locations, I believe that will not be possible

https://www.php.net/manual/en/function.header.php

0

The header() principle according to documentation is to keep a single page, you can not open two pages in one tab , that would eventually be an iframe but it is another story, if you want to act yet another redirect on the page /index.php/administradorlogistica the solution would be to create code inside that file that redirects you to /index.php/alertas3 but if you didn’t have an IF that determines the condition not to be redirected you could never access the page /index.php/administradorlogistica

Browser other questions tagged

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