PHP header Setcookie headers_sent function function checks if the HTTP header has been sent and where it was sent

Source: Internet
Author: User

The header () that needs attention here is most often taken to send the header (' Location:/'); And so on, do the Web redirect action.

In use Setcookie (), header () ... You cannot use any output before such a function. Log records if necessary.

If there is output then Headers_sent will return true.

I am using TP directly in the PHP command Runtime (PHP index.php/home/login/test) found no return output, view the discovery,

There is a $this->redirect ("") function, which calls the redirect function indirectly, as follows:

/**
* URL Redirection
* @param string $url The URL address of the redirect
* Wait time for @param integer $time redirect (seconds)
* @param string $msg Prompt before redirection
* @return void
*/
function Redirect ($url, $time =0, $msg = ") {
Multi-line URL address support
$url = Str_replace (Array ("\ n", "\ R"), ", $url);
if (empty ($msg))
$msg = "The system will automatically jump to {$url}! after {$time} seconds ";
if (!headers_sent ()) {
redirect
if (0 = = = $time) {
Header (' Location: '. $url);
} else {
Header ("refresh:{$time};url={$url}");
Echo ($msg);
}
Exit ();
} else {
$str = "<meta http-equiv= ' Refresh ' content= ' {$time}; url={$url} ' > ';
if ($time! = 0)
$str. = $msg;
Exit ($STR);
}
}

The description only executes the header (' Location: '. $url); Send to exit (); Command line run cannot receive the contents of the header currently do not know why?

If the header (' Location: ' $url), before the printout such as Echo can receive <meta http-equiv= ' Refresh ' content= ' 0; Url=./login/logout ' > information.

Please leave a message if you know.

PHP Header Setcookie headers_sent function function checks if the HTTP header has been sent and where it was sent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.