sprint10s Posted August 15, 2009 Share Posted August 15, 2009 This is the error im getting Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/www/standridgemotorsports.com/sponsor.php:11) in /home/www/standridgemotorsports.com/auth.inc.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/standridgemotorsports.com/sponsor.php:11) in /home/www/standridgemotorsports.com/auth.inc.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/www/standridgemotorsports.com/sponsor.php:11) in /home/www/standridgemotorsports.com/auth.inc.php on line 7 You are being redirected to the login screen! (If your browser does not support this, click here) below here is the auth file code <?php session_start(); if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) { // Do Nothing } else { $redirect = $_SERVER['PHP_SELF']; header("Refresh: 5; URL=login.php?redirect=$redirect"); echo "You are being redirected to the login screen!<br>"; echo "(If your browser does not support this, " . "<a href=\"login.php?redirect=$redirect\">click here</a>)"; die(); } ?> can anyone help me figure out whats going on. basically i got two other files a login.php and sponsor.php i want to protect the sponsor.php page so they have to login with the right credentials in order to see the contents of the sponsor.php page. thanks for any help Quote Link to comment Share on other sites More sharing options...
Markh789 Posted August 15, 2009 Share Posted August 15, 2009 <?php session_start(); if (isset($_SESSION['logged']) && $_SESSION['logged'] == 1) { // Do Nothing } else { $redirect = $_SERVER['PHP_SELF']; echo "You are being redirected to the login screen!<br>"; echo "(If your browser does not support this, " . "<a href=\"login.php?redirect=$redirect\">click here</a>)"; header("Refresh: 5; URL=login.php?redirect=$redirect"); die(); } ?> You can not echo after you send header() Read: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 15, 2009 Share Posted August 15, 2009 You can not echo after you send header() You have it backwards. All headers MUST be sent prior to any output. This means all calls to header() and all functions that send or modify headers as a side-effect, such as session_start(), MUST occur before any output has gone to the browser. You can not echo anything, not even a blank line, to the browser before the headers are sent. Quote Link to comment Share on other sites More sharing options...
sprint10s Posted August 15, 2009 Author Share Posted August 15, 2009 thanks, that was the problem i had a html doc line before the header instead of after. Works great now. Thanks. Quote Link to comment Share on other sites More sharing options...
Markh789 Posted August 15, 2009 Share Posted August 15, 2009 You can not echo after you send header() You have it backwards. All headers MUST be sent prior to any output. This means all calls to header() and all functions that send or modify headers as a side-effect, such as session_start(), MUST occur before any output has gone to the browser. You can not echo anything, not even a blank line, to the browser before the headers are sent. Ah, that is so - my bad. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.