You are here: Re: newbie: need help with "headers already sent" error « PHP Language « IT news, forums, messages
Re: newbie: need help with "headers already sent" error

Posted by Glenn O Larsen on 01/11/07 15:50

Jeff skrev:
> Jeff <it_consultant1@hotmail.com.nospam> wrote:
> Any suggestions?

Yes - If you want to send a "header" request, you are not allowed to
send kind of data to the client.

You are sending a bounch of HTML to the client, and then later trying a
"header".

See here:

> ************* complete index.php *********************
> <?php
> session_start();
> if ($_GET["mode"] == "logout") {
> header("Location: index.php");
> }
> ?>
>

Ok, here you start sending data.

> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
> <head>
> <title>DEMO</title>
[REMOVED MANY LINES]
> <?php
>
> if ($_GET["mode"] == 1)
> include 'search.php';
> else if ($_GET["mode"] == "reg")
> include 'registration.php';
> else if ($_GET["mode"] == "login")

and.. here you load the login.php file, that is trying to send a header
request.

> include('login.php');

> else if ($_GET["mode"] == "logout")
> include ('logout.php');


Your index.php - should be aomething like:

************* index.php *******************
<?php
session_start();
if ($_GET["mode"] == "logout") {
header("Location: index.php");
return;
} else if ($_GET["mode"] == 1)
include 'search.php';
// return ??
else if ($_GET["mode"] == "reg")
include 'registration.php';
// return ??
else if ($_GET["mode"] == "login")
include('login.php');
return;
else if ($_GET["mode"] == "logout")
include ('logout.php');
return;
else if ($_GET["mode"] == "profile")
include 'profile.php';
// return ??
else
include 'home.php';
?>

Your HTML code...
**********************************************

Remeber to do a "return" on the "include" files that is sending a header.

You should also use "switch" insted of "if / else if / else if"!


Good luck!


--
Glenn O Larsen

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация