Redirection of php pages

Asked

Viewed 1,098 times

0

header('Location: leticia.php?id=1' .$usuario);
header('Location: barbara.php?id=2' .$usuario);

I am trying to redirect 2 logged in users, each one to your page using the code above, but when logged in, redirects the 2 to the same page that is leticia.php, how to correct?

  • Maybe making a if checking which user is logged in?

  • I haven’t tried yet! I could write the code ?

  • Is there a different way to redirect ?

  • No, you understand what the HTTP header is Location? If not, it would be good to research on to understand how it works.

  • I’ll do a search. I could help with the code above?

  • Recommend redirecting with javascript window.Location = "arbara.php? id=2<? php echo $usuario; ? >"; sending cabling before html (DOCTYPE etc) would be the right way http://php.net/manual/en/function.header.php

Show 1 more comment

2 answers

1

$resultado_usuario = mysqli_query($Conn, $result_usuario); if($resultado_usuario){ $row_usuario = mysqli_fetch_assoc($resultado_usuario); if(password_verify($password, $row_user['password']){ $_SESSION['id'] = $row_usuario['id']; $_SESSION['name'] = $row_usuario['name']; $_SESSION['email'] = $row_usuario['email'];

    **header('Location: leticia.php?id=1' .$usuario);
    header('Location: barbara.php?id=2' .$usuario);**

}else{
    $_SESSION['msg'] = "Login e senha incorreto!";
    header("Location: login.php");
} esse é meu codigo.

0

Do the following:

if ($usuario == 1) {
    header('Location: leticia.php?id=1' .$usuario);
} else {
    header('Location: barbara.php?id=2' .$usuario);
}
  • I will test !!! Ronald.. I will need this for 13 users as I do ? Sorry to noobce kkk

  • I honestly don’t quite understand your code. For me, it doesn’t make much sense to have user names in php files (Ronald.php, Marcio.php, etc), but since this is your scenario use a switch http://php.net/manual/en/control-structures.switch.php

  • No.. these names are fictitious the page of each will not be that name, summarizing need to redirect BD users each to their page .

  • Got it. Then a switch solves, I guess.

  • 1

    <?php switch ($usuario) { case 1 header('Location: Leticia.php?id=1' .$usuario); case 2: header('Location: Barbara.php?' id=2' .$usuario); } ? > So?

  • ...............

  • Something like that. You wouldn’t have been able to put the full code in Pastebin?

  • Something like that. You wouldn’t have been able to put the full code in Pastebin?

  • $resultado_usuario = mysqli_query($conn, $result_usuario);&#xA;if($resultado_usuario){&#xA; $row_usuario = mysqli_fetch_assoc($resultado_usuario);&#xA; if(password_verify($senha, $row_usuario['senha'])){ $_SESSION['id'] = $row_usuario['id']; $_SESSION['name'] = $row_usuario['name']; $_SESSION['email'] = $row_usuario['email']; ; header('Location: Leticia.php? id=1' . $usuario); header('Location: Barbara.php? id=2' . $usuario); }Else{ $_SESSION['msg'] = "Incorrect login and password!" ; header("Location: login.php"); } .. below

Show 4 more comments

Browser other questions tagged

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