What is the purpose of using $_SERVER["path_info"] in PHP?

The $_SERVER["path_info"] variable in PHP is used to retrieve the path information provided in the URL after the script name. It can be useful for creating clean URLs or routing requests based on the path information. By accessing $_SERVER["path_info"], you can extract specific information from the URL to determine the appropriate action to take within your PHP script.

$path_info = $_SERVER["path_info"];

// Example usage:
if($path_info == '/about'){
    // Display the About Us page
    echo "Welcome to the About Us page";
} elseif($path_info == '/contact'){
    // Display the Contact Us page
    echo "Contact us at example@example.com";
} else {
    // Handle other paths or show a 404 error
    header("HTTP/1.0 404 Not Found");
    echo "404 Not Found";
}