Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

header already sent problems #26

Closed
PatrickCaneloDigital opened this issue May 18, 2017 · 3 comments
Closed

header already sent problems #26

PatrickCaneloDigital opened this issue May 18, 2017 · 3 comments
Labels

Comments

@PatrickCaneloDigital
Copy link

PatrickCaneloDigital commented May 18, 2017

I have a strange fenomenon:
On one subdomain (user tests) I am using the nearly same redirects but get no errors...
On the other subdomain (integration tests) I made a fresh install with a slight change (full domain - not relative header location calls) but got weird behaviour: It's actually not redirecting...
because Auth is already sending out headers...
But I have no clue why the code works in one subdomain, but in slight variation ( header('Location http://subdomain/folder/file.php) ) it doesn't... Specially why my change would provoke a different behaviour in Auth

representative Code (produces empty page, no redirect):
PD: Fact is: after running the code I am still logged in...

$AUTH->logout();
$_SESSION['preguntas_educacion'] = NULL;
$_SESSION['preguntas_postulacion'] = NULL;
?>
<?php if ($AUTH->isLoggedIn()): ?>
    <?php 
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/paso1.php"); ?>
<?php else: ?>
    <?php 
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/login.php"); ?>
<?php endif; ?>

Error:

Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 73

Warning: Cannot modify header information - headers already sent by (output started at /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:73) in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 87

Warning: Cannot modify header information - headers already sent by (output started at /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:73) in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 92

Warning: Cannot modify header information - headers already sent by (output started at /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:73) in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 94

Warning: Cannot modify header information - headers already sent by (output started at /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:73) in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 97

Warning: Cannot modify header information - headers already sent by (output started at /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:73) in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 98

Warning: Cannot modify header information - headers already sent by (output started at /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:73) in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 99

Fatal error: Uncaught exception 'Delight\Auth\HeadersAlreadySentError' in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php:320 Stack trace: #0 /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php(277): Delight\Auth\Auth->setRememberCookie(NULL, NULL, 1495128213) #1 /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php(371): Delight\Auth\Auth->deleteRememberDirective(50) #2 /home/user/subdomain.whatever.com/logout.php(15): Delight\Auth\Auth->logout() #3 {main} thrown in /home/user/subdomain.whatever.com/vendor/delight-im/auth/src/Auth.php on line 320

@rgvy
Copy link

rgvy commented May 18, 2017

I can confirm that I've had this issue (or one very similar). Unfortunately I don't have a test case, but my workaround was using \Delight\Cookie\Cookie::setcookie instead of $_SESSION

@PatrickCaneloDigital
Copy link
Author

SOLVED.... Trailing blanks before the <?php header('Location were the issue...

@ocram
Copy link
Contributor

ocram commented May 19, 2017

@rgvy Thanks for helping! That code change was probably only part of the workaround, or something else caused the problem to go away :)

@PatrickCaneloDigital Thanks for resolving the issue and for explaining what caused the problem in this specific case.

In general, the "headers already sent" error occurs whenever some output has been written to the response body and you still try to set or modify HTTP headers after that. This does not work, because as soon as you write text or binary data to the output, the server may send the HTTP headers (which go before the output) to the client. Often, this happens because you have accidentally written some whitespace to the output, as in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants