I don't know what this error means.

I just set up my server with a bunch of php which I'm fairly new to.

I got this error message when I sent to view my login page:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/hihatweb/public_html/Showdown/admin/default.php:1) in /home/hihatweb/public_html/Showdown/admin/default.php on line 5

I have the code attached, I wouldn't think it would cause any real problem. You can view the page by heading out to: http://hihatwebdesign.com/Showdown/admin/default.php

Thanks!
<?php require_once('header.php'); ?>
 
<?php
 
session_start();
switch (@$_POST['do'])
{
	case "login":
	$password='$_POST[password]';
	if (!$password="Secret")
	{
	header("Location:LoginWrong.php");
	exit ();
	}
	else
	{
	$_SESSION['auth'] = "yes";
	header("Location:admin.php");
	}
	break;
}
 
?>

Open in new window

brucegustPHP DeveloperAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
In your code, header.php is sending code immediately to the browser. The problem you encountered originally is because you were calling session_start() AFTER you used require_once('header.php'). Thus, the server begins sending data to the browser as soon as you execute require_once('header.php') AND then it attempts to start a session due to session_start().

You MUST call session_start() BEFORE your script begins sending data to the browser. The code you posted above (ID: 22889074) did not work because you are :
a. sending data via require_once
b. executing session_start
c. sending data via require_once (again - redundant call but not the reason for the error message. The problem is the first call , namely the one in step a).

On the fixed code I got rid of "step a" so that the session is started BEFORE your script begins sending data to browser!
0
 
KirrilianCommented:
What is in header.php? Sounds like there is something there that may be causing this.
0
 
hieloCommented:
try:
<?php 
session_start(); 
require_once('header.php'); 
 
switch (@$_POST['do'])
{
      case "login":
      $password='$_POST[password]';
      if (!$password="Secret")
      {
      header("Location:LoginWrong.php");
      exit ();
      }
      else
      {
      $_SESSION['auth'] = "yes";
      header("Location:admin.php");
      }
      break;
}
 
?>

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
hieloCommented:
also, after:
header("Location:admin.php");

you need exit();

..
else
      {
      $_SESSION['auth'] = "yes";
      header("Location:admin.php");
      exit();
      }
...
0
 
Cornelia YoderArtistCommented:
The usual cause of this error is sending some character (often a blank space) before the html starts.

Check each script and make sure you don't have a blank line at the start.
0
 
Cornelia YoderArtistCommented:
Ah, I see it right here:

<?php require_once('header.php'); ?>
 
<?php

If header.php has only php code in it. then remove the blank line between these:

<?php require_once('header.php'); ?>
<?php
0
 
brucegustPHP DeveloperAuthor Commented:
Alright, I've eliminated the extra space and applied hielo's code and still no luck...

Thing is, this worked fine on my local machine. It's only now when I'm running from my ISP that I'm having difficulty.

In any event, I have the code with the corrections posted below. My header.php looks like this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Colgate Country Showdown | America's Largest Country Music Talent Search | Admin Page</title>
<script language="javascript">AC_FL_RunContent = 0;</script>
<script src="../AC_RunActiveContent.js" language="javascript"></script>
<link href="../stylesheet.css" rel="stylesheet" type="text/css" />

<script language="JavaScript"><!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
// -->
</script>

</head>

<body bgcolor="#000000">

<table width=100% height=100% align="center" valign="center" cellspacing="0" cellpadding="0">
<tr>
<tr>
<td align="center" valign="top">&nbsp;<BR>
      <table width="1000" cellspacing="0" cellpadding="0">
      <tr>
      <td align="center">
      <!--url's used in the movie-->
      <!--text used in the movie-->
      <!-- saved from url=(0013)about:internet -->
      <script language="javascript">
      if (AC_FL_RunContent == 0) {
            alert("This page requires AC_RunActiveContent.js.");
      } else {
            AC_FL_RunContent(
                  'codebase', 'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
                  'width', '1000',
                  'height', '299',
                  'src', 'Header',
                  'quality', 'high',
                  'pluginspage', 'https://www.macromedia.com/go/getflashplayer',
                  'align', 'middle',
                  'play', 'true',
                  'loop', 'true',
                  'scale', 'showall',
                  'wmode', 'transparent',
                  'devicefont', 'false',
                  'id', 'Header',
                  'bgcolor', '#ffffff',
                  'name', 'Header',
                  'menu', 'true',
                  'allowFullScreen', 'false',
                  'allowScriptAccess','sameDomain',
                  'movie', 'Header',
                  'salign', ''
                  ); //end AC code
      }
      </script>
      <noscript>
      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="1000" height="299" id="Header" align="middle">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="allowFullScreen" value="false" />
      <param name="movie" value="Header.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" />      <embed src="Header.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="1000" height="299" name="Header" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />
      </object>
      </noscript>
      </td>
      </tr>
      <tr>
      <td background="../Images/Filler.jpg">&nbsp;<BR>

 <?php require_once('header.php'); ?>
<?php 
session_start(); 
require_once('header.php'); 
 
switch (@$_POST['do'])
{
      case "login":
      $password='$_POST[password]';
      if (!$password="Secret")
      {
      header("Location:LoginWrong.php");
      exit ();
      }
     else
      {
      $_SESSION['auth'] = "yes";
      header("Location:admin.php");
      exit();
      }
 
      break;
}
 
?>

Open in new window

0
 
hieloCommented:
on the last code you attached, get rid of line 1. It should just be:
<?php 
session_start(); 
require_once('header.php'); 
 
switch (@$_POST['do'])
{
      case "login":
      $password='$_POST[password]';
      if (!$password="Secret")
      {
      header("Location:LoginWrong.php");
      exit ();
      }
     else
      {
      $_SESSION['auth'] = "yes";
      header("Location:admin.php");
      exit();
      }
 
      break;
}
 
?>

Open in new window

0
 
brucegustPHP DeveloperAuthor Commented:
hielo!

The last post you sent made the difference! Can you tell me what you did because it looks like I'm going to have to do it on all my pages and I want to understand the "why" behind your suggestion and not just the fact that it worked.

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.