How do I make a redirect in PHP?
snippet in php

How do I make a redirect in PHP?

user4173

echo '<script type="text/javascript">
           window.location = "http://www.google.com/"
      </script>';

How do I make a redirect in PHP?

user9726

function Redirect($url, $permanent = false)
{
    if (headers_sent() === false)
    {
        header('Location: ' . $url, true, ($permanent === true) ? 301 : 302);
    }

    exit();
}

Redirect('http://www.google.com/', false);

How do I make a redirect in PHP?

user8016

header("Location: myOtherPage.php");
die();

How do I make a redirect in PHP?

user9429

<?php
    session_start();

    if (!isset( $_SESSION["valid_user"]))
    {
        header("location:../");
        exit();
    }

    // Page goes here
?>

How do I make a redirect in PHP?

user6931

$url = 'http://' . $_SERVER['HTTP_HOST'];            // Get the server
$url .= rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); // Get the current directory
$url .= '/your-relative/path-goes/here/';            // <-- Your relative path
header('Location: ' . $url, true, 302);              // Use either 301 or 302

How do I make a redirect in PHP?

user8916

function Redirect($url, $code = 302)
{
    if (strncmp('cli', PHP_SAPI, 3) !== 0)
    {
        if (headers_sent() !== true)
        {
            if (strlen(session_id()) > 0) // If using sessions
            {
                session_regenerate_id(true); // Avoids session fixation attacks
                session_write_close(); // Avoids having sessions lock other requests
            }

            if (strncmp('cgi', PHP_SAPI, 3) === 0)
            {
                header(sprintf('Status: %03u', $code), true, $code);
            }

            header('Location: ' . $url, true, (preg_match('~^30[1237]$~', $code) > 0) ? $code : 302);
        }

        exit();
    }
}

How do I make a redirect in PHP?

user9954

header("Location: /index.php");
exit(0);   

How do I make a redirect in PHP?

user9079

header("Location: http://example.com/redirect_page.php");
die(); //Force the script to quit, or you would raise an error...