Irresistable Posted November 1, 2009 Share Posted November 1, 2009 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jeanie/public_html/Newsletter Beta/activate.php:6) in /home/jeanie/public_html/Newsletter Beta/include/session.php on line 30 Line 30 is session_start(); //Tell PHP to start the session function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session } Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/ Share on other sites More sharing options...
Daniel0 Posted November 1, 2009 Share Posted November 1, 2009 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948894 Share on other sites More sharing options...
Irresistable Posted November 1, 2009 Author Share Posted November 1, 2009 I've looked at that before posting this, I'm not sure what I have to actually do, I don't understand the error. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948897 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2009 Share Posted November 1, 2009 Line 30 is session_start(); //Tell PHP to start the session Yes, but the cause of the problem is the output that is started on line 6 of activate.php - output started at /home/jeanie/public_html/Newsletter Beta/activate.php:6 You either need to find and fix what is causing that output (assuming it is not intended at all), move the session_start() to the beginning of your page (where it generally belongs in any case), or move the output so that it occurs after the session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948900 Share on other sites More sharing options...
Daniel0 Posted November 1, 2009 Share Posted November 1, 2009 Lazy loading it is perfectly fine, but it requires that you've abstracted it away and that the application flow is clearly defined (at least in terms of output). For instance Zend_Session is lazy loaded by default. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948901 Share on other sites More sharing options...
Irresistable Posted November 1, 2009 Author Share Posted November 1, 2009 I played around with the php.. putting it in different places. When I now click on the link to activate the newsletter account.. it should say stuff either "code is invalid" or "your acount has been activated" but.. neither comes up. <? include("include/session.php"); ?> <!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="Content-Type" content="text/html; charset=utf-8" /> <title>Developers Community - Currently Down</title> <style type="text/css"> <!-- #wrapper h1 { color: #F00; font-style: normal; } --> </style> <style> div#wrapper { margin-left: auto; margin-right: auto; width: 825px; text-align: center; font-weight: bold; font-family: "Comic Sans MS", cursive; color: #000; }.text { text-align: center; font-family: "Comic Sans MS", cursive; color: #F00; } .forever { font-style: italic; } </style> <div id="wrapper"> <h1 class="forever"><u>Developers Community</u></h1> <p>You will be redirected to the homepage within 10 seconds.<br /> If you do not get redirected please click <a href="http://www.developers-community.com" class="text">here<br /> <br /> </a> <?php session_start(); include ('include/constants.php'); if (!isset($_GET['email']) && !isset($_GET['code']) ) { $msg = "ERROR: Invalid code..."; exit(); } $rsCode = mysql_query("SELECT activ_code from email where email='$_GET[email]'") or die(mysql_error()); list($acode) = mysql_fetch_array($rsCode); if ($_GET['code'] == $acode) { mysql_query("update users set activated=2 where email='$_GET[email]'") or die(mysql_error()); echo "<h3>Thank you </h3>Email confirmed and account activated. You are now subscribed to the Developers Community newsletter!"; } else { echo "ERROR: Incorrect activation code...not valid"; } ?> </p></div> I got a feeling.. it's not getting the email and the code from the database, to see if its correct and matches with the code sent to the customers email address, along with there email. Though I'm not sure how to do that bit, i'm able to do it if I had it as a registration.. with a username etc. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948925 Share on other sites More sharing options...
Daniel0 Posted November 1, 2009 Share Posted November 1, 2009 session_start() must be before any output is sent because it involves sending headers and headers are always before the body of an HTTP response. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948926 Share on other sites More sharing options...
Irresistable Posted November 1, 2009 Author Share Posted November 1, 2009 Where should I put it then? Because there is a session start at the beginning of session.php, but I used roughly the same format as my login system, and the session starts are in the same place, so I don't understand why it dont work. If I remove the session.start from the activate.php - nothing displays aswell. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948931 Share on other sites More sharing options...
Daniel0 Posted November 1, 2009 Share Posted November 1, 2009 Before you send output the first time. Note that things outside of PHP tags count as "sending output". Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948939 Share on other sites More sharing options...
Irresistable Posted November 1, 2009 Author Share Posted November 1, 2009 what do I modify it in, activate.php ? Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948954 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2009 Share Posted November 1, 2009 It is highly likely that session.php is NOT being included in the following code because of the <? tag - <? include("include/session.php"); ?> Please only use full php opening tags <?php to insure that your php code will be seen as being php code. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948955 Share on other sites More sharing options...
Irresistable Posted November 1, 2009 Author Share Posted November 1, 2009 Im not too sure that session.php is needed, but I did put the <?php tag in. I've also moved the session.start on that page to the top of the page, and it still never worked. edit: I used the "error_reporting(E_ALL);" This came up when running the activate.php script. Notice: A session had already been started - ignoring session_start() in /home/jeanie/public_html/Newsletter Beta/activate.php on line 43 It's ignoring session start so that'd be why nothing appears to say if the code is invalid etc. How would I get it so it registers the session. <?php include("database.php"); include("mailer.php"); include("form.php"); class Session { var $referrer; //Last recorded site page viewed /* Class constructor */ function Session(){ $this->time = time(); $this->startSession(); /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session } function register($subemail, $subuser_code){ global $database, $form, $mailer; //The database, form and mailer object /* Email error checking */ $field = "email"; //Use field name for email if(!$subemail || strlen($subemail = trim($subemail)) == 0){ $form->setError($field, "*Email not entered "); } else{ /* Check if valid email address */ $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, "*Email invalid "); $subemail = stripslashes($subemail); } else if($database->emailTaken($subemail)){ $form->setError($field, "*Email already been subscribed "); } } /* Captcha error chcking */ $field = "captcha"; //Use field name for gender if (strcmp(md5($subuser_code),$_SESSION['ckey'])){ $form->setError($field, "*Captcha image is incorrect"); } /* Errors exist, have user correct them */ if($form->num_errors > 0){ return 1; //Errors with form } /* No errors, add the new account to the database */ else{ $activ_code = rand(1000000,9999999); if($database->addNewUser($subemail, $activ_code)){ if(EMAIL_WELCOME){ $mailer->sendWelcome($subemail,$activ_code); } return 0; // New user added succesfully }else{ return 2; //Registration attempt failed } } } }; $session = new Session; /* Initialize form object */ $form = new Form; ?> That is where the session is first started, but i set it as new session; at the bottom? So it should be able to start new session on activate.php. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948957 Share on other sites More sharing options...
Irresistable Posted November 2, 2009 Author Share Posted November 2, 2009 However.. if I removed all the session_start's from activate.php .. it stops displaying that a session has been started so its ignoring session_start on line blah. Or if I placed session start right at the top of the code. Though, if I did this.. it doesn't create a session for the actual activation. So.. the page still displays blank. Maybe it'd be easier to recode it.. as the script works.. without any activation in place. I easily coded it sweetly (created the activation code etc) set it so when you subscribe before activation.. the collumn "activated" in the database is set as 1 by default. You recieve an email, with the link. At the moment its set as something like "http://www.developers-community.com/Newsletter Beta/activate.php?$activ_code$email" When you click on the link, its suppose to check see if the activation code submitted, is the same as the one in the database as submitted when you clicked submit on the form. (It generates a activation key, puts it in the database so it can be used to check if its valid with the user wanting to activate). If it matches, then activated collumn .. will turn to "2" instead of "1" 1= not activated 2= activated If it'd be easier to .. recode the whole script on that page.. could you do it for me, because I've no idea.. Sorry if I sound dumb about all this. Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-948974 Share on other sites More sharing options...
Irresistable Posted November 2, 2009 Author Share Posted November 2, 2009 Does anyone know what to do? Quote Link to comment https://forums.phpfreaks.com/topic/179875-solved-warning-session_start-functionsession-start-error/#findComment-949218 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.