How to redirect the user to a specific PHP page?

Asked

Viewed 254 times

0

I would like to know how to redirect the user to the page I want as soon as they log in? example

login:diego.santos password:12345 wanted you to redirect to id1.php example

login:santos. password:12345 wanted you to redirect to id2.php example

2 answers

0

You must use the function header, for example:

/** Redirecionar o usuário para /home.php: */
header('Location: /home.php');

Link to the documentation.

An important observation:

You can only use this function before sending any reply to the customer, given that it is a response header.

To learn more, consider reading that question and answer.

0

It’s best if you create tags for each user and check the tags, but if you want something basic you can use this code:

if($nome == "diego.santos" && $password == "12345"){
header('Location: id1.php');
}else if($nome == "santos.diego" && $password == "12345"){
header('Location: id2.php');
}

This is a quick example and is not a correct way to Login

  • What would be the right way ? I need to redirect 10 users each to your page.

  • It depends a lot on what you’re using and what you have access to, if you’re using a database and you have a unique id for each user you can do so header('Location: id' . $userid . '.php')

  • Dude .. in the comic book each one has an id ! Now I needed to make each one, so logging in was for some page I chose .

Browser other questions tagged

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