Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Php Header Problem, i always got header problem
adly3000
post Feb 5 2006, 10:53 PM
Post #1


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 31-January 06
Member No.: 17,937



i really hate the header function it always get an error saying (cannot ------- headers already sent by-----)
and here's my error:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/adly3000/public_html/Mail/index.php:5) in /home/adly3000/public_html/Mail/index.php on line 81

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/adly3000/public_html/Mail/index.php:5) in /home/adly3000/public_html/Mail/index.php on line 81

Warning: Cannot modify header information - headers already sent by (output started at /home/adly3000/public_html/Mail/index.php:5) in /home/adly3000/public_html/Mail/index.php on line 90

i don't know why it can not :send session cookie , send session cache limiter, or modify header information. and what do it mean (headers already sent [output started] )
what is output started refers to?!!!! i have not an echo?!!!! unsure.gif
Go to the top of the page
 
+Quote Post
xJedix
post Feb 5 2006, 11:37 PM
Post #2


Premium Member
********

Group: Members
Posts: 183
Joined: 27-June 05
From: Minnesota
Member No.: 8,734



It would be useful to actually see the code to figure out specifically what is wrong..... But I have also had this issue..... For some reason php doesn't like spaces in the header. So try to remove all line spaces before the main part of the code/site, or the start of the <?php

When I had this issue, I had something like this

CODE
<?php
if ($username == NULL) {

  $username = $usercook;

  $password = $passcook;

}
    setcookie("usercook","$username",time()+5000,"/");

    setcookie("passcook","$password",time()+5000,"/");

?>

<?php
rest of code


When I was doing this type of stuff, that space in between the php codes messed it all up and gave me those errors.

So just try removing the space so it looks like this

CODE
<?php
if ($username == NULL) {

  $username = $usercook;

  $password = $passcook;

}
    setcookie("usercook","$username",time()+5000,"/");

    setcookie("passcook","$password",time()+5000,"/");

?>
<?php
rest of code


This could be the issue your having or something else.... From what you gave me, that's the only thing I can think of.

Hope it helps
Go to the top of the page
 
+Quote Post
Yarrgh
post Feb 6 2006, 02:26 AM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 21
Joined: 6-February 06
Member No.: 18,277



It would help a lot to have the code you use (header part) posted.

QUOTE
<?php
if ($username == NULL) {

$username = $usercook;

$password = $passcook;

}
setcookie("usercook","$username",time()+5000,"/");

setcookie("passcook","$password",time()+5000,"/");

?>
<?php
rest of code


Why not just put the code in one <?php ... ?> ?
Go to the top of the page
 
+Quote Post
kvkv
post Feb 6 2006, 02:36 AM
Post #4


Newbie [Level 3]
***

Group: Members
Posts: 40
Joined: 29-January 06
Member No.: 17,841



The "headers already sent [output started]" refers to any html content which has been written to the browser. When browser requests a page, the http server sends http headers before html contents. It means that if you are using php to send any headers, it must be done before writing any html output. Html output need not be just echo statement, but can be spaces or newline before the php tag (<?) because anything outside php tags is considered to be html. It is not that php (or any serverside scripting language for that matter -- like jsp or cgi-perl or asp) doesn't like spaces or newline, but it is the correct way it is supposed to behave.

Make sure that you don't output anything to the browser before header function and no spaces/newline outside php tags and your problem will be solved.
Go to the top of the page
 
+Quote Post
Yarrgh
post Feb 6 2006, 02:52 AM
Post #5


Newbie [Level 1]
*

Group: Members
Posts: 21
Joined: 6-February 06
Member No.: 18,277



The easiest thing to do is to seperate HTML from PHP. Make templates or something then use PHP to use that when everything that needs to be done is done. That way you don't have to worry about headers always giving you an error. And be sure you are not sending anything to the user in PHP before you start sending the headers. Or it will give you an error everytime.

Also, after you send the headers you cannot resend them later on. If I am wrong about this let me know.
Go to the top of the page
 
+Quote Post
silentwind
post Feb 6 2006, 05:35 AM
Post #6


Newbie
*

Group: Members
Posts: 7
Joined: 2-February 06
Member No.: 18,052



simple javascript function should fix that problem :
CODE

?>
<script language="javascript">
  top.location.replace("http://www.path.you.want.to.redirect//");
</script>
<?php


And about your error. It's because you have allready echo an output that is produced by your error.
error = output some html code.
Go to the top of the page
 
+Quote Post
adly3000
post Feb 6 2006, 07:04 AM
Post #7


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 31-January 06
Member No.: 17,937



thanks all for replying;
here's the lines 1-9: it says the problem is at line 5:
CODE
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
   .labelstyle {FONT-SIZE: 13PX; FONT-FAMILY: tahoma, Arial, Helvetica, sans-serif}
   .inputstyle {BACKGROUND: #ffffff; COLOR:#006699; FONT-FAMILY:tahoma, Arial, Helvetica, sans-serif; FONT-SIZE:13; BORDER-RIGHT: #006699 1px solid; BORDER-LEFT: #006699 1px solid; BORDER-TOP: #006699 1px solid; BORDER-BOTTOM: #006699 1px solid}
</style>
<script language="JavaScript">

as you can see its the css, which i can't remove!!!!

and here's what i hope to do:
1- if the form did not submit echo form;
2- if the form submitted then:
i- register the login data in session variables for later use.
ii- header("Location: page.php");

final question:
$hi = "welcome"; is that an output or i can assign any variables before the header?
Go to the top of the page
 
+Quote Post
Spectre
post Feb 6 2006, 11:43 AM
Post #8


Privileged Member
*********

Group: Members
Posts: 873
Joined: 30-July 04
Member No.: 246



If there is a posibility that PHP is going to send headers based on the outcome of something yet to be processed, you need to do all processing before any output is sent - ie. above the '<html>'. The second any output is sent, the headers are sent with it, and they can never be recalled and modified. Remember that PHP only deals with what's between the <?php ?> (or <? ?> depending on the configuration) tags, and everything else is ignored and instantly sent as output.

CODE
<?php
// Any processing code needs to go here.
?><html>
<head>
<title>Untitled Document</title>


I think this is about the 8,455,794th thread relating to exactly the same problem started on Trap17.
Go to the top of the page
 
+Quote Post
Amezis
post Feb 6 2006, 12:39 PM
Post #9


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



As everyone else have told you, the header function must be BEFORE the <html> tag. You can also have other PHP code before, but no HTML code.