Jump to content

Recommended Posts

I'm getting this strange error everytime I add a cookie, I did search it on google, but no headers were matching the cookie.

 

Warning: Cannot modify header information - headers already sent by (output started at url) in url on line 25

 

url is obviously a replacement for the original error spot, the error line is below.

 

setcookie ("Epic-Missions", $escape2,time()+3600) or die('Make sure you have cookies enabled!');

 

The make sure you have cookies enabled show also, any clue what's wrong?

Link to comment
https://forums.phpfreaks.com/topic/208852-header-error/
Share on other sites

You have some form of output which is causing the error. You should note anything outside of your <?php ?> tags is considered output, and also when you're echoing/printing etc.

 

In order to solve this you need to find out where the output is comming from. This is actually given to you within the error message, eg

Warning: Cannot modify header information - headers already sent by (output started at YOUR URL HERE:LINE NUMBER IS GIVEN HERE ON FIRST INSTANCE OF OUTPUT) in url on line 25

However you have sensored too much information for me to tell you where the output is.

Link to comment
https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090965
Share on other sites

The error is pretty self-explanatory. You can't send anything to the browser, not even whitespace, before sending headers. Something on line 25 is outputting to the browser, and setcookie() comes after line 25, correct?

Link to comment
https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090967
Share on other sites

The error is pretty self-explanatory. You can't send anything to the browser, not even whitespace, before sending headers. Something on line 25 is outputting to the browser, and setcookie() comes after line 25, correct?

 

No, after line 25 includes:

echo("<html><meta HTTP-EQUIV='REFRESH' content='0; url=ucphome.php?page=ucp'></html>");

You have some form of output which is causing the error. You should note anything outside of your <?php ?> tags is considered output, and also when you're echoing/printing etc.

 

In order to solve this you need to find out where the output is comming from. This is actually given to you within the error message, eg

Warning: Cannot modify header information - headers already sent by (output started at YOUR URL HERE:LINE NUMBER IS GIVEN HERE ON FIRST INSTANCE OF OUTPUT) in url on line 25

However you have sensored too much information for me to tell you where the output is.

 

The line number i'm guessing you're asking for in the "LINE NUMBER IS GIVEN HERE..." is below.

 

$server = mysql_connect($HOST,$USER, $PASSWORD) OR DIE ('Unable to connect to database! Please try again later.');

 

Link to comment
https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090969
Share on other sites

Paste in the code, from the beginning to about line 40. Change any passwords/database credentials before posting it . . .

 

<!-- PHP Basic Script Includes -->
<?php include("MySQL.php"); ?>
<?php include("ScriptBegin.php"); ?>
<!-- PHP Include Header -->
<?php include("header.php"); ?>
<!-- Content -->
    <!-- content begins -->
    <div id="content">
        	<div id="right">
            	<h2>UCP</h2>
           	  <div class="text">
        <p><span>UCP</span> </p>
        <p>
        <?php 
					$escape = mysql_real_escape_string($_POST['password']);
					$escape2 = mysql_real_escape_string($_POST['username']);
					$query = mysql_query("SELECT * FROM Accounts WHERE Name ='" . $escape2 . "' AND Password = md5(sha1('" . $escape . "'))") or die('Cannot Execute:'. mysql_error());
					$amount = mysql_num_rows($query);
					if($amount > 0) {
						setcookie ("Epic-Missions", $escape2,time()+3600) or die('Make sure you have cookies enabled!');
						echo("<html><meta HTTP-EQUIV='REFRESH' content='0; url=ucphome.php?page=ucp'></html>");
					}
					else {
						echo("<html>Your username or password is incorrect, click <a href='UCP.php'>here</a> to try again.<br /></html>");
					}

					?></p>
           	  </div>
           	  <div></div>
            </div>
		<?php include("Top20.php"); ?>
    </div>
    <!-- PHP Footer Includes -->
    <?php include("Footer.html"); ?>
</div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090974
Share on other sites

Output to the browser starts on the very first line. The setcookie() is after that. Nothing at all can be sent to the browser before sending headers. Read the (at least) first paragraph of the PHP manual for setcookie().

Link to comment
https://forums.phpfreaks.com/topic/208852-header-error/#findComment-1090980
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.