Lamez Posted January 11, 2008 Share Posted January 11, 2008 alright, on my registration page, I made it where you enter a code before you can register, well after you enter the code correct, it gives me these errors: Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /mounted-storage/home48c/sub007/sc33591-LWQU/lamezz.info/style/include/pwcode.php:194) in /mounted-storage/home48c/sub007/sc33591-LWQU/lamezz.info/style/include/session.php on line 45 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /mounted-storage/home48c/sub007/sc33591-LWQU/lamezz.info/style/include/pwcode.php:194) in /mounted-storage/home48c/sub007/sc33591-LWQU/lamezz.info/style/include/session.php on line 45 here is line 45 of session.php: session_start(); when I take this line out, the registration does not work. any help? Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/ Share on other sites More sharing options...
sKunKbad Posted January 12, 2008 Share Posted January 12, 2008 put the session_start at the very top of the script after <?php Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436927 Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 There's a topic on this at the top of this forum: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436930 Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 I tried putting it at the top, nothing, same error. I have also read that thread, before posting. I am not too sure what is wrong, should I post some more code? Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436935 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 Post the top of the code for a few lines. If you use a editor like Dreamweaver, they usually put ascii characters before your PHP code. Use a .txt editor and remove them then re-upload it. Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436938 Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 Here is some of the code session.php: <? /** * Session.php * * The Session class is meant to simplify the task of keeping * track of logged in users and also guests. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 19, 2004 */ include("database.php"); include("mailer.php"); include("form.php"); class Session { var $username; //Username given on sign-up var $userid; //Random value generated on current login var $userlevel; //The level to which the user pertains var $time; //Time user was last active (page loaded) var $logged_in; //True if user is logged in, false otherwise var $userinfo = array(); //The array holding all user info var $url; //The page url current being viewed var $referrer; //Last recorded site page viewed /** * Note: referrer should really only be considered the actual * page referrer in process.php, any other time it may be * inaccurate. */ /* Class constructor */ function Session(){ $this->time = time(); $this->startSession(); } /** * startSession - Performs all the actions necessary to * initialize this session object. Tries to determine if the * the user has logged in already, and sets the variables * accordingly. Also takes advantage of this page load to * update the active visitors tables. */ function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session /* Determine if user is logged in */ $this->logged_in = $this->checkLogin(); I do not think it is session.php, I think it is this file: pwcode.php: <?php ############################################################### # Page Password Protect 2.13 ############################################################### # Visit http://www.zubrag.com/scripts/ for updates ############################################################### # # Usage: # Set usernames / passwords below between SETTINGS START and SETTINGS END. # Open it in browser with "help" parameter to get the code # to add to all files being protected. # Example: password_protect.php?help # Include protection string which it gave you into every file that needs to be protected # # Add following HTML code to your page where you want to have logout link # <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a> # ############################################################### /* ------------------------------------------------------------------- SAMPLE if you only want to request login and password on login form. Each row represents different user. $LOGIN_INFORMATION = array( 'zubrag' => 'root', 'test' => 'testpass', 'admin' => 'passwd' ); -------------------------------------------------------------------- SAMPLE if you only want to request only password on login form. Note: only passwords are listed $LOGIN_INFORMATION = array( 'root', 'testpass', 'passwd' ); -------------------------------------------------------------------- */ ################################################################## # SETTINGS START ################################################################## // Add login/password pairs below, like described above // NOTE: all rows except last must have comma "," at the end of line $LOGIN_INFORMATION = array( 'work' => 'test' ); // request login? true - show login and password boxes, false - password box only define('USE_USERNAME', false); // User will be redirected to this page after logout define('LOGOUT_URL', 'http://www.lamezz.info/'); // time out after NN minutes of inactivity. Set to 0 to not timeout define('TIMEOUT_MINUTES', 160); // This parameter is only useful when TIMEOUT_MINUTES is not zero // true - timeout time from last activity, false - timeout time from login define('TIMEOUT_CHECK_ACTIVITY', true); ################################################################## # SETTINGS END ################################################################## /////////////////////////////////////////////////////// // do not change code below /////////////////////////////////////////////////////// // show usage example if(isset($_GET['help'])) { die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>'); } // timeout in seconds $timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60); // logout? if(isset($_GET['logout'])) { setcookie("verify", '', $timeout, '/'); // clear password; header('Location: ' . LOGOUT_URL); exit(); } if(!function_exists('showLoginPasswordProtect')) { // show login form function showLoginPasswordProtect($error_msg) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="style/default.css"/> <link rel="shortcut icon" href="style/img/favicon.ico"> <title>Registration Code</title> </head> <body> <div class="body"> <div class="logo"><img src="style/img/logo.png" alt="March Madness Logo" border="0"/></div> <?php include ("style/include/cons/nav.php"); ?> <div class="box"> <h2>Registration Code</h2> <form method="post"> <table width="378" border="0"> <tr> <td width="62" align="left">Code</td> <td width="150" align="left"><input type="password" name="access_password" /></td> <td width="152" align="left"><font color="red"><?php echo $error_msg; ?></font></td> </tr> <tr> <td align="left"> </td> <td align="left"><input name="Submit" type="submit" id="Submit" value="Continue" /></td> <td align="left"> </td> </tr> </table> </form> </div> <div class="footer"> Site Template & Original Site Content<br /> © 2007-2008 <a href="mailto:wizkid916@yahoo.com">James Little</a> </div> </div> </body> </html> <?php // stop at this point die(); } } // user provided password if (isset($_POST['access_password'])) { $login = isset($_POST['access_login']) ? $_POST['access_login'] : ''; $pass = $_POST['access_password']; if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION) || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) ) { showLoginPasswordProtect("* Invalid Code"); } else { // set cookie if password was validated setcookie("verify", md5($login.'%'.$pass), $timeout, '/'); // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed // So need to clear password protector variables unset($_POST['access_login']); unset($_POST['access_password']); unset($_POST['Submit']); } } else { // check if password cookie is set if (!isset($_COOKIE['verify'])) { showLoginPasswordProtect(""); } // check if cookie is good $found = false; foreach($LOGIN_INFORMATION as $key=>$val) { $lp = (USE_USERNAME ? $key : '') .'%'.$val; if ($_COOKIE['verify'] == md5($lp)) { $found = true; // prolong timeout if (TIMEOUT_CHECK_ACTIVITY) { setcookie("verify", md5($lp), $timeout, '/'); } break; } } if (!$found) { showLoginPasswordProtect(""); } } print '</div>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436941 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 You can't set your cookies after output to the browser, you have to set them before. Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436943 Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 You can't set your cookies after output to the browser, you have to set them before. Maybe I missed it, but I don't see where he is outputing anything before the setcookie(). All I see is just a die() before the setcookie(). Anyway, Lamez you have to check each of those included files and make sure the each don't output ANYTHING, including before a starting PHP tag and after an ending PHP tag. So much as one space or line will cause this. If you can't find where, then use ob_start() at the beginning of your script for now (this should be looked at as a band-aid and not a permanent solution). Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436946 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 He tries to set a cookie a 2nd time at the bottom of pwcode.php I didn't follow all the logic, but it was under html output, so chances are something is getting sent out. Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436951 Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 Lamez, revraz is correct. You have all that HTML output and a condition towards the end that could potential call a setcookie() after all that HTML output has already occurred. Rethink your logic or use output buffering (ob_start). Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-436954 Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 oh thanks guys, I downloaded the script, I really did not read over the script. So I need to move my cookies Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-437001 Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 If it's not your code, then post in third party script topic area instead. Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-437005 Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 well, the session.php is my code, that is why I asked here sorry. please answer this: do I need to remove some cookies, if so where? Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-437013 Share on other sites More sharing options...
revraz Posted January 12, 2008 Share Posted January 12, 2008 You don't need to remove them, you need to restructure your code so if you do need a cookie it comes before any output to the browser Quote Link to comment https://forums.phpfreaks.com/topic/85617-how-do-i-fix-this/#findComment-437049 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.