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