Jump to content

[SOLVED] why am i getting this warning - Cannot modify header information (see below) ?


jd2007

Recommended Posts

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\Freelance Project 1\addarom.php:20) in C:\AppServ\www\Freelance Project 1\addarom.php on line 21

 

this is addarom.php:

<?php
session_start();
header("Cache-control: private");

$h=$_GET["var3"];
if ($_POST["gamename"] && $_POST["gamelink"] && $_POST["gameromno"] && $_POST["scode"])
{
if ($_POST["scode"]==$h)
{
  
}
else
{
  echo "The security code doesn't match.";
  header("location:index.php");
}
}
else
{
echo "Please make sure all fields are filled.";
header("location:index.php");
}

?>

 

what's wrong ? pls help...

You can't do...

 

<?php

echo "Please make sure all fields are filled.";
header("location:index.php");

?>

 

If you want to pass a notice or error to the next page do it through the url...

 

<?php

header("location:index.php?error=$error");

?>

 

Then grab it on the next page...

 

<?php

  $notice = $_GET['error'];

?>

Not sure what you mean by that...my example was showing that you can determine what error they made so that you can then use a conditional statement to echo out a notice in the page they are redirected to.

 

Example...

 

<?php


    if(isset($_GET['error'])) {

    $error = $_GET['error'];
      
      if($error == 'wronguser') {
        echo'You did not enter the correct username';
      }

      if($error == 'wrongpass') {
        echo'You did not enter the correct password';
      }

    }

?>

 

Etc...etc. You can of course use swirches...or in fact...use a different approach altogether...but the point was, you can't echo out something and then output the header.

<!--Use of sessions-->
<?php 
session_start();
header("Cache-control: private");
?>

<html>
<head>

<title>Nintendo ROMS</title>

</head>

<body>

<!--logo-->
<img  class="logo" src="images/logo.png" alt="Nintendo ROMS Logo" width="50" height="20">

<!--login/logged area-->
<?php
if ($_SESSION["username"])
{
echo "<b>Hi, $_SESSION[username] </b><br><br>
      <b>You have $_SESSION[credits]</b>";
}
else 
{
echo "
<form method='post' action='loggingin.php'>
Username:<input type='text' name='login_username'>
Password:<input type='password' name='login_password'>
<input type='submit' value='Log In'>
</form><br><br>
<span class='a'><a href='register.html'>Register Here</a></span>
<span class=''><a href=''>Forgot Your Login ?</a></span>";
}
?>

<!--game list-->
<?php
if (!$_SESSION["username"])
{
$db=mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("ndsrom");
for ($_id=1; $_id<5; $_id++) {
$query="SELECT name, worked, notworked, romno FROM games WHERE id='$_id'";
$result=mysql_query($query); 
$row = mysql_fetch_row($result);
$total=$row[1]+$row[2];

echo "<span class='a'><pre>  $row[0]    $row[3]    This link worked for $row[1] out of $total people.  DID THIS LINK WORK FOR YOU ? <a href='worked.php'>YES</a>      <a href='notworked.php'>NO</a>  </pre></span>";


}
}
else if ($_SESSION["admin"]==0)
{



$db=mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("ndsrom");
for ($_id=1; $_id<14; $_id++) {
$query="SELECT name, worked, notworked, romno, link FROM games WHERE id='$_id'";
$result=mysql_query($query); 
$row = mysql_fetch_row($result);
$total=$row[1]+$row[2];

//<span style='background-color:#CCCCCC;'>

echo "<pre>  <a href='$row[4]'>$row[0]</a>      $row[3]    This link worked for $row[1] out of $total people.  DID THIS LINK WORK FOR YOU ? <a href='worked.php?var=$_id'>YES</a>      <a href='notworked.php?var=$_id'>NO</a> </pre> ";

//</span>
//<br>


}
}
else if ($_SESSION["admin"]==1)
{
$x=0;
$db=mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db();
for ($_id=1; $_id<5; $_id++) {
$query="SELECT name, worked, notworked, romno FROM games WHERE id='$_id'";
$result=mysql_query($query); 
$row = mysql_fetch_row($result);
$total=$row[2]+$row[3];

echo "<span class='a'><pre>  $row[0] <a href='deletegames.php'>[x]</a> <a href='editgames.php'>[-]</a>     $row[3]    This link worked for $row[1] out of $total people.  DID THIS LINK WORK FOR YOU ? <a href='worked.php'>YES</a>      <a href='notworked.php'>NO</a>  </pre></span>";
echo "<br>";

}
}
else {}
?>

<!--add a rom-->
<?php
$w=rand(1,10);
$w=substr($w,0,2);
$y=md5(rand(1,10));
$y=substr($w,0,2);
$z=$w.$y;
echo "
<form method='post' action='addarom.php?var3=$z'>
Game Name: <input type='text' name='gamename'>
Game Download Link: <input type='text' name='gamelink'><br><br>
ROM Number: <input type='text' name='gameromno'>
Language:"; 
$lang=array('English', 'Japanese', 'Other');
echo "<select name='language'>";
for ($i=0; $i<count($lang); $i++) {



echo "<option value=$lang[$i]>$lang[$i]</option>";



}
echo "</select>";
echo "<br><br>";

echo "Enter this code $z here:";
echo "<input type='text' name='scode'>";
        /*
        header ("Content-type: image/png");
        $img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
        $back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
        $txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
        ImageString ($img_handle, 31, 5, 5,  $z, $txt_color);
        ImagePng ($img_handle);
        */
echo "<input type='submit' value='Add'>";        
echo "</form>";     


?>

</body>
</html>

 

can u check what wrong with the code above ? i'm getting this :

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\Freelance Project 1\index.php:2) in C:\AppServ\www\Freelance Project 1\index.php on line 4

 

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\Freelance Project 1\index.php:2) in C:\AppServ\www\Freelance Project 1\index.php on line 5

You're outputting something before the header again. Remove your comment at the top of the page, make sure you don't leave any white space before the opening PHP tag, and add your comments after...within the PHP (using PHP comments with slashes or '/* Comment here */')...and also initialize the session after the header function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.