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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
hieloCommented:
also, after:
header("Location:admin.php");

you need exit();

..
else
      {
      $_SESSION['auth'] = "yes";
      header("Location:admin.php");
      exit();
      }
...
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

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
hieloCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.