i hate header function always getting problems.

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
adly3000
php-forum Fan User
php-forum Fan User
Posts: 55
Joined: Thu Apr 08, 2004 4:39 pm
Location: Egypt
Contact:

Sun Feb 05, 2006 3:11 pm

i always getting error in header function so i need help for know how to us i avioded it alot but no way i need it, here's some of errors which always appear to me:

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
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 824
Joined: Sun Jun 02, 2002 3:09 am

Sun Feb 05, 2006 3:17 pm

simple

just dont give any out put to broser before to make session_start().

ways to do that
1) buffering http://php.net/ob_start
2) templating smarty.php.net
3) cheking for whitspaces, and other chars than can be displaed...


actualy in your case its very simple just look what a header given to browser in line # 5
disable it - and anjoy!
Coditor
php-forum GURU
php-forum GURU
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands
Contact:

Sun Feb 05, 2006 4:05 pm

Note that line 5 probably doesn't contain a header but does produce output to the browser. Perhaps an echo or an error that you didn't paste here.

As soon as any output is sent to the browser, PHP has to prepend it with a header. Once output has been sent to the browser, the header has been sent and closed and cannot be modified. All header manipulation (including sessions) must therefor be done before any output (including mentioned whitespace).

Using the output buffer (as Oleg suggested) is good if you cannot avoid sending output.

Coditor
adly3000
php-forum Fan User
php-forum Fan User
Posts: 55
Joined: Thu Apr 08, 2004 4:39 pm
Location: Egypt
Contact:

Sun Feb 05, 2006 5:33 pm

thanks Oleg Butuzov, and Coditor;
here's the lines 1-9:

Code: Select all

<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">
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?
Post Reply