Jump to content

[SOLVED] Warning: session_start() [function.session-start]: - error


Irresistable

Recommended Posts

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
}

Link to comment
Share on other sites

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().

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.