Redirect system with PHP [closed]

-2

Hello, how could I make a page redirect system with PHP? Being more specific, it would be the following, I have a page of tests with only 2 inputs, one to send and another to insert a text. If it enters a certain code correctly it is redirected to some page, otherwise an error message appears to it (but nothing like an alert in the middle of the screen, I'm more to make a small stylized box containing some text appear, for example " Code nonexistent ").  For example, let's say I have these 4 codes: teste1 teste2 teste3 teste4  

They would be like passwords, if the user types the teste1 it is redirected to the página1.php if you enter the teste2 it is redirected to the página2.php and so it goes ..
 But if he does not enter anything, the error appears as I mentioned.

    
asked by anonymous 07.04.2014 / 21:17

1 answer

2

You can do something like the example below:

<?php
var $campo = $_POST["campo"];
switch($campo) {
    case "teste1":
        header("Location: teste1.php");
    // mais casos
    case "testeN":
        header("Location: testeN.php");
    default: 
        echo "<div class='box-estilizada-erro'>Código inválido</div>";
}

But if they are codes that are registered dynamically, or if they are many, I recommend to make a table in bank and to check there if this code exists, then if it exists, it does the redirection, if not, it displays the message.     

07.04.2014 / 21:44