KB0129 2023. 5. 7. 05:02

Today, I learned about the URL Redirection in PHP.

 

  • Manual redirect
    • The simpest technique is to ask the visitor to follow a link to the new page, usually using an HTML anchor like:
Please follow <a href="https://www.example.com/">this link</a>
  • Using server-side scripting for redirection
    • One can use the "header" function:
header("HTTP/1.1 301 Moved Permanetly");
header("Location: https://www.example.com/");
exit();

 

Header()

 

Example:

<?php
	session_start();
    if (isset($_POST['type'])) {
    	header("Location: user.php");
        return;
    }
    else if ($_POST['type'] == 'manager'){
    	header("Location: manage.php");
        return;
    }
    else {
    	header ("Location: http://www.~.edu");
        return;
    }
}
?>