Jump to content
xisto Community
Sign in to follow this  
adly3000

Php Header Problem i always got header problem

Recommended Posts

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 81Warning: 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 81Warning: 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 (see edit history)

Share this post


Link to post
Share on other sites

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

<?phpif ($username == NULL) {  $username = $usercook;  $password = $passcook;}	setcookie("usercook","$username",time()+5000,"/");	setcookie("passcook","$password",time()+5000,"/");?><?phprest 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

<?phpif ($username == NULL) {  $username = $usercook;  $password = $passcook;}	setcookie("usercook","$username",time()+5000,"/");	setcookie("passcook","$password",time()+5000,"/");?><?phprest 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

Share this post


Link to post
Share on other sites

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

<?phpif ($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 (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

simple javascript function should fix that problem :


?><script language="javascript"> top.location.replace("http://forums.xisto.com/no_longer_exists/;);</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(\"yourredirectURL;); </script>"; if($success) { echo $redirect; } else { echo "Whatever you want"; } CHEERS


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.