Unexpected blank rows in the header or errors in output and Cookie settings

Source: Internet
Author: User
PHPsetcookie () orPHPheader ('Location: ') NotWorking? WithSolutionThesetcookie () orheader () functionsofPHPdoesnotworkatall! ThePHPsetcookie () andheader () shouldbecalledbe

PHP setcookie () or PHP header ('Location: ') Not Working? With SolutionThe setcookie () or header () functions of PHP does not work at all!

The PHP setcookie () and header () shocould be called before ANY browser output. if there are any echo or print cils, or any accidental whitespaces, those functions just won't work. if it works on your localhost (strangely it does under some conditions !) But not on your server, check for the no-output-before-headers violations and fix them to get them working.

Explanation
HTTP headers shoshould be sent before any HTTP content, else they will not work. the PHP header () function is used for sending standard as well as custom HTTP headers, so naturally they shoshould be called before any browser output. setcookie () is a wrapper function to header ('set-Cookie: '), so ultimately it's a header () call, so setcookie () too will not work if it's called after any browser output.

Notes

The PHP header () function is used for sending standard as well as custom HTTP headers
Header () shocould be called before any browser output
Setcookie () shocould be called before any browser output
Setcookie () is a wrapper function to header ('set-Cookie :')
Html> http://www.hacksparrow.com/php-setcookie-or-php-headerlocation-not-working-with-solution.html

Additional tips:

This is why it is better not to use the close symbol at the end of the PHP file.

Echo hello world;

?>

The reason, because it is very likely that the blank lines and blank characters other than the input of this closed line

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.