Page 1 of 1

Getting Header Error Help!

Posted: Wed Mar 24, 2004 1:26 am
by fadi
Hi!
i m getting following error on header. can any one help me.

Cannot modify header information - headers already sent by (output started at index.php:9) in index.php on line 19.

plz help me out. i need to work on project.

Posted: Wed Mar 24, 2004 1:35 am
by zaibe
This will happen sometimes when you have some html tags just before sending header so make shure you are not putting any html stuff above that header() function

Posted: Wed Mar 24, 2004 11:33 am
by werlop
hey what zaibe said is true, but i would like to extend that by saying that ANYTHING, even whitespace, that is output before you send the header will cause the problem, as the headers will already have been sent.

If you wan't to post your code, we will have a look.

Posted: Wed Mar 24, 2004 11:58 am
by malcolmboston
use the following code in various places in your files and you will be able to narrow down the problem

Code: Select all

if (headers_sent())
{
print "headers were already sent above";
}
else
{
print "headers havent been sent yet, the problem is below";
hope that helps

Posted: Wed Mar 24, 2004 10:45 pm
by fadi
Hi Buddies thanx for help . Here's my code which is getting header error!.
<?php

$_REQUEST['username'];
$_REQUEST['password'];
session_start();

if (! isset($_SESSION['password'])) {
session_register("username");
session_register("password");
$_SESSION['password']=$_REQUEST['password'];
}
$passwd=$_SESSION['password'];
$pas='abc';

if(!session_is_registered('password'))
{echo "not registered";}
else
{ echo "session registerd";}

if($pas==$_REQUEST['password']){
$valid_user = 1;
}
else {
$valid_user = 0;
}


if ($valid_user==1)
{
echo "Suces";
// echo "$passwd";
header("Location: index.php");
}
else
{
session_unset();
session_destroy();
echo "Not a Valid User";
}

?>

And I have also tried using headers_sent() function that really narrowed down my problem. But couldnt solve it. thats pretty close to that. i just want to redirect User from current page to the Index Page.

Posted: Wed Mar 24, 2004 11:19 pm
by markl999
You can't echo anything out before the header("Location: index.php");
There's no point sending something to the user if you're about to redirect them to another page anyway :o

Posted: Thu Mar 25, 2004 3:15 am
by fadi
thanx ! Markl999.

You made a valid point. There is really no point sending user info if they're to redirect. we can show them message at redirected page.that worked..Thanx alot...

Now Mark Would You Plz tell me how to use templates in php ? plz tell me the most easiest way to use them and from where i can download their libraries or classes.

and wot variables are needed to set in 4.3.4 version of PHP. i installed it on my windows xp machine with IIS through PHP Installer.
All i want is to create such a project which should run on every version of PHP irrespective of Server version of PHP.

Thanx in Advance..

Posted: Thu Mar 25, 2004 3:57 am
by patrikG
fadi wrote:Now Mark Would You Plz tell me how to use templates in php ? plz tell me the most easiest way to use them and from where i can download their libraries or classes.
The search feature on this board is quite powerful. Type in "template engines" and you'll get plenty of topics discussing your question

Reg. your second question: have a look at the tutorial section of this board.

Before you do that, please read the General Posting Guidelines, especially point 1 (click on the first link in my sig).