php header location vs php_redirect

后端 未结 3 1474
广开言路
广开言路 2021-01-06 02:19

What\'s the difference between the function \"HTTP_redirect\" and \"header location\" in PHP ?

When must I use the function \"HTTP_re

相关标签:
3条回答
  • 2021-01-06 02:33

    Header forwards the user to a new page, so PHP reinitializes, it's like a HTML meta redirection, but faster.

    0 讨论(0)
  • 2021-01-06 02:37

    http_redirect is basically a helper function, making it easier to use header location by allowing you to pass an array for GET data.

    0 讨论(0)
  • 2021-01-06 02:40

    1) Header in PHP

    header() function sends a raw HTTP header to a client.

    <?php
    header("HTTP/1.0 404 Not Found");
    ?>
    

    The above (taken from the PHP documentation) sends a 404 header back to the client.

    2) HTTP Redirect

    Redirect to the given url.

    <?php
    http_redirect("relpath", array("name" => "value"), true, HTTP_REDIRECT_PERM);
    ?>
    

    The above (taken from the PHP documentation) : Output

    HTTP/1.1 301 Moved Permanently
    X-Powered-By: PHP/5.2.2
    Content-Type: text/html
    Location: http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc
    
    Redirecting to <a href="http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc">http://www.example.com/curdir/relpath?name=value&PHPSESSID=abc</a>.
    
    0 讨论(0)
提交回复
热议问题