PHP page redirection


Answers ( 1 )


    1. Using the header() function:

    The most common method is using the header() function to send a raw HTTP header to the browser. Here's an example:

        // Redirect to another page

    Important Notes:

    • The header() function must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
    • It is a good practice to call exit; after headers to avoid further script execution.

    2. Using JavaScript:

    You can also use JavaScript for redirection. This is useful when you need to add a delay or condition before redirecting.

        echo '<script>window.location.href="";</script>';

    3. Using HTML Meta Refresh:

    Another way to redirect is by using the HTML meta refresh tag. This is not recommended for SEO purposes but can be used for temporary redirections.

        echo '<meta http-equiv="refresh" content="0;url=">';

    Each method has its use cases depending on the specific requirements of your project, such as the need for delayed redirection, server-side vs. client-side redirection, or handling the redirection after some PHP logic is processed.

Leave an answer