从Php switch语句重定向到外部链接[重复]

This question already has an answer here:

I would like to know if i can redirect my web page to an external web page from a Php switch statement without the use of html (purely Php). I have made a username/password login using the $_POST predefined variable which is linked to a switch statement which from there depending on what is inputted will auto redirect the user to an external web page. I do not want to have to click on an echoed link, i would much rather have the web page auto directed. Can someone please tell me if this is possible or what other method should I use.

</div>

Try this code. this would definetely help you.

<?php
     $location = 'https://www.google.co.in';   //change url as per your requirement
      header('Location:' . $location);
 ?>

Use:

header("Location:pathtoTheExternalwebpage");

Make sure you don't echo any html codes or anything in the web browser before using this statement.(Not even a space ' ')

It's easy. I have written a very simple function for you, here it goes:

<?php
    function redirect($source) {
        switch ($source) {
            case 'login':
                header("Location: login.php");
            break;

            default:
                header("Location: {$source}");
            break;
        }
    }
?>

Usage: If you will call function like redirect('login');, it will redirect to login.php or if you will call it like redirect('http://externalpage.com');, it will redirect to the external URL specified.

Specify your own conditions to this function and you can add more functionality easily.