Jump to content

[SOLVED] Cannot modify header information error..


sspoke

Recommended Posts

Hello im having this error on atleast 5 pages (login,register,inside logged in page,forgotpassword) and it doesn't seem to redirect after seccessful login or register etc..

 

Warning: Cannot modify header information - headers already sent by (output started at C:\shttps\www\newproject\utils.php:70) in C:\www\newproject\mysession.php on line 85

 

Warning: Cannot modify header information - headers already sent by (output started at C:\shttps\www\newproject\utils.php:70) in C:\www\newproject\register.php on line 95

 

I know headers have to be first of any page but this worked yesterday I did no changes at all expect for defining new database settings and new host..

 

 

it says output started at utlis.php line 70 but that script edits at line 68 with a ?>  ..

 

mysession.php line 85 is     

setcookie("sessionid",$sessionid,0,'/','',0);

 

register is the page im calling and it starts off line this

 

<? 
require_once("alldefines.php");
require_once("mysession.php");

and line 95 is where error on register.php is

 

95.   			header("Location: " . REGISTER_DONE);
96.    			return;
97.    		}
98.		}
99.		break;
100.	}

?>

 

 

alldefines.php has

 

define(REGISTER_DONE,"registerc.php");

 

I been trying to fix it but no progress its....

 

well any help would help possibly

Link to comment
Share on other sites

Have you tried buffering the output ? If there is any HTML or anything echoed to the browser before the header() call, the header will not redirect (becasuse at that point the header has been sent to the browser).

 

Try adding:

ob_start();

 

to he first line of your script. And also check any required/included scripts to make sure they do not echo or print anything to the browser before your header() call.

Link to comment
Share on other sites

but dangit I haven't even edited it nothing and it worked before and there is none html code or echos ill post full script of register

 

<? 
require_once("definings.php");
require_once("mysession.php");


$errormsg = "";

while (isset($register))
{
	if ($username == "")
	{
		$errormsg = "Please choose a username.";
	}
	else if ($password == "")
	{
		$errormsg = "Please choose a password.";
	}
	else if (strlen($password) < 
	{
		$errormsg = "Please choose a password of at least 8 characters.";
	}
	else if ($password != $password_verify)
	{
		$errormsg = "The passwords you entered do not match. Please try again.";
	}
	else if ($email == "")
	{
		$errormsg = "Please enter your email address.";
	}
	else if (!isset($agree))
	{
		$errormsg = "Please read and agree to the Terms of Service before registering.";
	}
	else
	{

    		// make db connection
    		mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
    		mysql_select_db(DB_NAME);
    		
    		// first check that the username and email aren't already registered
    		$query = "SELECT username FROM users where username='$username'";
    		$result = mysql_query($query);
    		if (mysql_num_rows($result) > 0)
    		{
    			$errormsg = "The username you have chosen is already taken. Please choose a different one.";
    			break;
    		}
    		
    		$query = "SELECT email FROM users where email='$email'";
    		$result = mysql_query($query);
    		if (mysql_num_rows($result) > 0)
    		{
    			$errormsg = "The email you have chosen is already registered. If you have forgotten your password, " .
    						"<a href=\"" . PAGE_FORGOT_PASSWORD . "?email=$email\">click here</a>.";
    			break;
    		}
    		
    		if (isset($newsletter)) $newsletter = 1;
    		else $newsletter = 0;
    		
    		$query = "INSERT INTO users(username,password,firstname,lastname,email,last_login,newsletter) " .
    				 "VALUES('$username',md5('$password'),'$firstname','$lastname','$email',now(),'$newsletter')";
    		$result = mysql_query($query);
    		
    		if (!$result)
    		{
    			$errormsg = "Sorry, could not execute query: " . mysql_error();
    		}
    		else
    		{
    			$userinfo->userid = mysql_insert_id();
    			/*$userinfo->username = $username;
    			$userinfo->password = md5($password);
    			$userinfo->firstname = $firstname;
    			$userinfo->lastname = $lastname;
    			$userinfo->email = $email;
    			$userinfo->newsletter = $newsletter;
    			*/
    			
    			//session_start();
    			//session_register("userinfo");
    			
    			mysession_set($userinfo->userid);
    			
    			/*
    			$message = "A new user has registered at bakabb.net: \n\n" .
    					   "Username: $username, email: $email.\n\n" .
    					   "From: $REMOTE_ADDR, $HTTP_USER_AGENT\n";
    					   
    			$headers = "From: register@bakabb.net";
    			mail("test@mac.com","your registration",$message,$headers);
    			*/
    			
    			header("Location: " . REGISTER_DONE);
    			return;
    		}
	}
	break;
}

?>

<?require("header.php")?>

<form action="<?=$REQUEST_URI?>" method=POST>
<table border="0" width="100%">
  <tr>
    <td width="100%" colspan="2">
    <b>Thank you for trying out Bakabb.net.</b><br>
    
    Please complete the following form to register at Bakabb.net.<br>
    <i>If you have already registered but have forgotten your password, <a href="<?=PAGE_FORGOT_PASSWORD?>">click here</a></i>.<br><br>
    Fields in <b>bold</b> are required.
    </td>
  </tr>
  <tr>
    <td width="7">
      
    </td>
    <td width="100%">
        <table border="0" width="100%">
          <tr>
            <td width="165" valign="top"><b>Desired username</b><br>
              <input type="text" name="username" size="20" value="<?=$username?>">
            </td>
            <td width="506" valign="top"></td>
            <td width="16" valign="top"></td>
          </tr>
          <tr>
            <td width="165" valign="top"></td>
            <td width="506" valign="top"></td>
            <td width="16" valign="top"></td>
          </tr>
          <tr>
            <td width="165" valign="top"><b>Password</b><br>
              <input type="password" name="password" size="20">
            </td>
            <td width="506" valign="top"><b>Verify password</b><br>
              <input type="password" name="password_verify" size="20">
            </td>
            <td width="16" valign="top"></td>
          </tr>
          <tr>
            <td width="165" valign="top"></td>
            <td width="506" valign="top"></td>
            <td width="16" valign="top"></td>
          </tr>
          <tr>
            <td width="165" valign="top">First name<br>
              <input type="text" name="firstname" size="32" maxlength="32" value="<?=$firstname?>">
            </td>
            <td width="506" valign="top">Last name<br>
              <input type="text" name="lastname" size="32" maxlength="32" value="<?=$lastname?>">
            </td>
            <td width="16" valign="top"></td>
          </tr>
          <tr>
            <td width="165" valign="top"></td>
            <td width="506" valign="top"></td>
            <td width="16" valign="top"></td>
          </tr>
          <tr>
            <td width="165" valign="top"><b>Email</b><br>
              <input type="text" name="email" size="32" maxlength="32" value="<?=$email?>"> 
            </td>
            <td width="528" valign="top" colspan="2"></td>
          </tr>
          <tr>
            <td width="100%" valign="top" colspan="3"> 
              If you forget your password, a new password will be emailed to you.<br>
              <input type="checkbox" name="newsletter" <?=(isset($newsletter) ? "checked" : "")?>>Check here if you would like to receive announcements concerning BakaBB.</td>
          </tr>
          <tr>
            <td width="100%" valign="top" colspan="3"><input type="checkbox" name="agree" <?=(isset($agree) ? "checked" : "")?>>I agree to the <a href="javascript:void(0)" onClick="openTOS();">Terms of Service and Privacy Policy.</a></td>
          </tr>
          <tr>
            <td width="100%" valign="top" colspan="3"><input type="submit" name="register" value="Register"></td>
          </tr>
          <tr>
            <td width="100%" valign="top" colspan="3"><font color="red"><?=$errormsg?></font></td>
          </tr>
           	
        </table>
    </td>
  </tr>
  
</table>
</form>


<?require("footer.php")?>

 

 

mysession.php has no echos just a bunch of functions  definings only has define()'s no html no echos

 

only include in mysessions.php is definings and utils i commented out ultils include and removed all its calls and still errors

Link to comment
Share on other sites

Says I cant edit my last reply.. anyways I wanted to add that out of the 2 modify header information - header already errors

 

removing the

 

  //  setcookie("sessionid",$sessionid,0,'/','',0);

 

removes one of the 2 errors.. but how is setcookie related its needed and I dont see any way around it

Link to comment
Share on other sites

The cause of the error is on line 70 in utils.php as indicated by the error message (important bits highlighted in red).

 

Warning: Cannot modify header information - headers already sent by (output started at C:\shttps\www\newproject\utils.php:70) in C:\www\newproject\mysession.php on line 85

 

 

The problem is not with mysession.php, but utils.php. Also the other errors you are getting are caused by the first error. SO if you fix the first error message then all other errors will go away

 

Post lines 65 - 75 here from utils.php.

Link to comment
Share on other sites

ya I fixed it a while ago wanted this topic to die.. i cant edit it to say SOLVED like other topics do.. It was a blank line after.  the last ?>

You dont need to edit the title to mark it solved any more. Just mark it solved by clicking the Solved button at the bottom of the page before the quick reply box and it does it for you. Looks like some one has already done it for you.

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.