aebstract Posted January 30, 2008 Share Posted January 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/ Share on other sites More sharing options...
themistral Posted January 30, 2008 Share Posted January 30, 2008 Instead of include "$page.php"; try include('page.php'); Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453720 Share on other sites More sharing options...
aebstract Posted January 30, 2008 Author Share Posted January 30, 2008 All that did was make me get an error saying it can't open page.php. How does this solve the header problem? I've never had a problem with doing it the other way, ever. Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453730 Share on other sites More sharing options...
aebstract Posted January 30, 2008 Author Share Posted January 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453734 Share on other sites More sharing options...
themistral Posted January 30, 2008 Share Posted January 30, 2008 I was just ruling stuff out - fair enough if that's the way you do it but I am only trying to help. Think the problem may be in the login.php file. Can you post the code and we'll have a look! Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453750 Share on other sites More sharing options...
aebstract Posted January 30, 2008 Author Share Posted January 30, 2008 I did post it, the entire login.php file, in the first post? Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453755 Share on other sites More sharing options...
laffin Posted January 30, 2008 Share Posted January 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453756 Share on other sites More sharing options...
aebstract Posted January 30, 2008 Author Share Posted January 30, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453758 Share on other sites More sharing options...
themistral Posted January 30, 2008 Share Posted January 30, 2008 Sorry - tired and clearly paying absolutely no attention to what I'm reading Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453759 Share on other sites More sharing options...
themistral Posted January 30, 2008 Share Posted January 30, 2008 Right, what else is in your index.php file - if you have written stuff to the browser before that snippet of php code then that will cause the header problem. Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453761 Share on other sites More sharing options...
aebstract Posted January 30, 2008 Author Share Posted January 30, 2008 my index page just has an include mid way down the page for whatever page, this one happening to be login.php. Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453776 Share on other sites More sharing options...
PFMaBiSmAd Posted January 30, 2008 Share Posted January 30, 2008 (output started at ....index.php:32) Your index.php file is outputting content to the browser at or before line 32. If you want specific help in solving your problem, you need to post index.php at least through line 32. Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453785 Share on other sites More sharing options...
aebstract Posted January 30, 2008 Author Share Posted January 30, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453786 Share on other sites More sharing options...
themistral Posted January 30, 2008 Share Posted January 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453790 Share on other sites More sharing options...
MatthewJ Posted January 30, 2008 Share Posted January 30, 2008 Even better... You're already sending a header in the index file on line 3... headers already sent... wonder what that could mean Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453793 Share on other sites More sharing options...
MatthewJ Posted January 30, 2008 Share Posted January 30, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/88611-solved-sigh-header-problem/#findComment-453802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.