Posted by Serge Terryn on 01/12/07 14:25
Jeff schreef:
> Hey
>
> I'm using php 5.2.0 to create a web site. The Problem is that when logging
> in I get the "headers already sent by " already sent error. In the login.php
> (see below) this script is executed: header("Location:
> index.php?mode=profile"); if user is successfully authenticated. This script
> causes the "headers already sent by" error...
>
> I don't know how to solve this error.. I guess I get it because the header
> is already sent, but <head> always come before <body>... I think I have
> rewrite some of this code to avoid this error, but I'm not sure about how to
> do it...
>
> Based on my code posted below (index.php and login.php), what do you think
> is the easiest way of solving this error?
>
> Best Regards
>
> ************* index.php *******************
> <?php
> session_start();
> if ($_GET["mode"] == "logout") {
> header("Location: index.php");
> }
> ?>
> <!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>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <link rel="stylesheet" type="text/css" href="menu.css" media="all" />
> </head>
> <body>
> <?php
> if ($_GET["mode"] == 1)
> include 'search.php';
> else if ($_GET["mode"] == "reg")
> include 'registration.php';
> else if ($_GET["mode"] == "login")
> include('login.php');
> else if ($_GET["mode"] == "logout")
> include ('logout.php');
> else if ($_GET["mode"] == "profile")
> include 'profile.php';
> else
> include 'home.php';
> ?>
> </body>
> </html>
>
> *************** login.php ********************
>
> <?php
> $username = $_POST["username"];
> $password = $_POST["password"];
> require_once('authentication.php');
> if (isset($username) && isset($password)) {
>
> try {
> login($username, $password);
> //include('profile.php');
> header("Location: index.php?mode=profile");
> }
> catch (Exception $e) {
> CreateLoginBox($e->getMessage());
> }
> }
> else {
> CreateLoginBox("");
> }
> ?>
>
>
Put just under the <?php tag :
ob_start();
--
Posting at the top because that's where the cursor happened to be,
is like shitting in your pants because that's where your asshole
happened to be.
http://www.essetee.be
[Back to original message]
|