Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
Photo
- - - - -

Php Header Problem i always got header problem


12 replies to this topic

#1 adly3000

adly3000

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 58 posts

Posted 05 February 2006 - 10:53 PM

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?!!!! Posted Image

Edited by moderator, 21 May 2012 - 12:42 PM.

  • 0

#2 xJedix

xJedix

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 183 posts
  • Location:Minnesota
  • Interests:Computers :)

Posted 05 February 2006 - 11:37 PM

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

<?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

<?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
  • 0

#3 Yarrgh

Yarrgh

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 21 posts

Posted 06 February 2006 - 02:26 AM

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

<?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 ... ?> ?

Edited by moderator, 21 May 2012 - 12:43 PM.

  • 0

#4 kvkv

kvkv

    Newbie [Level 3]

  • Kontributors
  • PipPipPip
  • 40 posts

Posted 06 February 2006 - 02:36 AM

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.
  • 0

#5 Yarrgh

Yarrgh

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 21 posts

Posted 06 February 2006 - 02:52 AM

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.
  • 0

#6 silentwind

silentwind

    Newbie

  • Kontributors
  • Pip
  • 7 posts

Posted 06 February 2006 - 05:35 AM

simple javascript function should fix that problem :
?>
<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.
  • 0

#7 adly3000

adly3000

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 58 posts

Posted 06 February 2006 - 07:04 AM

thanks all for replying;
here's the lines 1-9: it says the problem is at line 5:
<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?
  • 0

#8 Spectre

Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 06 February 2006 - 11:43 AM

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.

<?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.
  • 0

#9 Amezis

Amezis

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 535 posts
  • Location:Oslo, Norway

Posted 06 February 2006 - 12:39 PM

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.
  • 0

#10 antony2kx

antony2kx

    Newbie [Level 2]

  • Kontributors
  • PipPip
  • 35 posts

Posted 13 February 2006 - 09:55 PM

you know that you can jump in and out of php just write the html headers or the wml headers without stsrting with <?php and between the header and the footer you can just write you php script or code thet you want to use

Edited by antony2kx, 13 February 2006 - 09:55 PM.

  • 0

#11 iGuest

iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 18 August 2008 - 11:47 AM

php header
Php Header Problem

Well. If you really want to redirect users using php then you have to use a buffer or send the header before the anything else is sent.
  • 0

#12 iGuest

iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 18 August 2008 - 11:48 AM

Replying to Amezis
Dude. Get your facts right. If you buffer your code you can use header after having sent html or any other code to the browser.
  • 0

#13 Guest_kamal chapagain_*

Guest_kamal chapagain_*
  • Guests

Posted 13 May 2011 - 12:47 AM

simple javascript function should fix that problem :

?>
<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.


Hi, that was really a good idea and here is the code
$redirect = "<script language=\"javascript\">
top.location.replace(\"http://yourredirectURL\page.php\");
</script>";

if($success) {
echo $redirect;
}
else { echo "Whatever you want"; }

CHEERS
  • 0



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users