How to Redirect URL with Message

AuthorSumit Dey Sarkar

Pubish Date22 Mar 2023


In this tutorial we will learn how to redirect URL with message.


How to redirect URL with message

To redirect a URL with a message, you can use HTTP status code 307, which stands for "Temporary Redirect" and indicates that the requested resource has been temporarily moved to a different location. This will allow you to redirect the user to a different URL while also sending a message.


Here's an example of how you can implement this in PHP:

$message = "Redirecting to";
$url = "";
header("HTTP/1.1 307 Temporary Redirect");
header("Location: " . $url);
echo $message;

In this example, we first define the message that we want to display to the user, and the URL that we want to redirect them to. We then set the HTTP status code to 307 using the header() function, and specify the location header to redirect the user to the new URL. Finally, we echo the message so that it is displayed to the user.


Note: It's important to use the header() function before any output is sent to the browser, otherwise the redirect will not work.

Comments 0

Leave a comment