Jump to content

[SOLVED] sigh... header problem


aebstract

Recommended Posts

Yes, I know about the topic at the top for headers. I also know how to use headers, though I have tried about everything I can think of and still can't get this to work.

 

I've jumped back and forth between "cannot add header information" and "header information already sent". These scripts are working without that being a problem before I was actually including the files.

 

 

login.php:

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

if(isset($_SESSION["id"]))
{
header("Location: index.php?menu=acchome");
}


if(!isset($_SESSION["id"]))
{

if (isset ($_POST['submit']))
{

$problem = FALSE;


      if (empty ($_POST['password'])) {
$problem = TRUE;
$error .= 'You must fill in a password <br />';
      }




if (!$problem) {

mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error());
mysql_select_db("berryequipment_net");

$result = mysql_query("SELECT id, plantloc, password, city, state, zip, street FROM plants WHERE id=('$_POST[dropdown]') AND password=('".md5($_POST['password'])."')") or die ("error");
            if (mysql_num_rows($result) == 0)
              {
echo 'The pasword you entered did not match the plant location you chose.';
} else {

                      $worked = mysql_fetch_array($result);
    			    $_SESSION["id"] = $worked[id];

                      header("Location: index.php?page=acchome");
}




}

}

}





echo "$error";


$content .= '

<form action="index.php?page=login" method="post">
   plant loc<br />

<select name="dropdown">';

mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error());
mysql_select_db("berryequipment_net");

$result = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC") or DIE(mysql_error());
while ($r=mysql_fetch_array($result)) {

$id=$r["id"];
$plantloc=$r["plantloc"];

$content .= "<option value=\"$id\">$plantloc</option>\n";

}


$content .= '</select>


             <br /><br />
   password <br />
   <input type="password" maxlength="6" class="textfield" name="password" value="' . $_POST[password] . '" size="6" /><br /><br />
   <input type="submit" name="submit" class="textfield" value="login" />


</form>';


echo "$content";
?>

 

This page is simply being included in to the body of the index file. The only php on that page is:

<?php

if (isset($_GET['page'])) {
$page = ($_GET['page']);
} else {
$page = "home";
}

include "$page.php";
?>

 

I've tried the header cache control thing at the top of my index.php page but that didn't work, still did the header sent already error.

I'm sure it's real simple and real stupid, please help if you see what is going on. Thanks

Link to comment
Share on other sites

put the header cache-control at the top of index page and removed from login, and now get this error when I submit my login script:

 

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site130/fst/var/www/html/2/index.php:30) in /home/virtual/site130/fst/var/www/html/2/login.php on line 41

Link to comment
Share on other sites

after this:

header("Location: index.php?page=acchome");

add this

exit();

 

I dun think u want to continue processing the script when u reach this point, you want it to go to that page.

But php dusn know this and continues processing the script, thus the error headers already sent.

Link to comment
Share on other sites

Now I am getting:

 

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site130/fst/var/www/html/2/index.php:32) in /home/virtual/site130/fst/var/www/html/2/login.php on line 6

 

Line 6 being the header () line in the code.

It also kills the rest of my page after that error instead of displaying it. (cause of the exit)

Link to comment
Share on other sites

Now I have:

 

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site130/fst/var/www/html/2/index.php:30) in /home/virtual/site130/fst/var/www/html/2/login.php on line 3

 

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site130/fst/var/www/html/2/index.php:30) in /home/virtual/site130/fst/var/www/html/2/login.php on line 8

 

Here is my index.php up to 30

 

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

if (isset($_GET['page'])) {
$page = ($_GET['page']);
} else {
$page = "home";
}
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Berry Plumbing & Equipment</title>

<link href="stylesheet.css" rel="stylesheet" type="text/css" title="default" />
</head>
<body>



<div id="container">


<div id="center">
	<div id="header"></div>
	<div id="topright"></div>
	<div id="user"></div>

Link to comment
Share on other sites

Well it's because you are writing content before the header is sent.

 

Any header stuff should be done before

 

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

which is where the content starts being sent to the browser.

Link to comment
Share on other sites

As a response to your personal message to me:

 

you know what dude... you are jerk to people through this entire thread... To people that are only trying to help you I might add!

 

I was ribbing you a bit, either get some thicker skin, or go off and code by yourself as you don't seem to know what joking and politeness are.

 

Hope being a surly jerk is a happy way for you to live...

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.