Jump to content

header error ... i have read the post at the top already


Recommended Posts

hi there, seems like I'm getting a fairly common beginners php error but as I'm using a number of differant files and as I'm not entirley clear on

a couple of things I thought I'd tap into the immense php talent on this site ;)

 

here's the error -

 

Warning: Cannot modify header information -

headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\index.php:4)

in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\ot\views\header.php on line 38

 

 

I have an index page that allows a user to log on, the processing go's away and checks the usual stuff then reloads the login page with the user

detail or just reloads the login page with the user/password fields blank. This seemed to be working ok until I put my files onto another web server

that had output_buffering turned off.

 

here's part of the login page

<html>
<head><title></title></head>
<body>
<?php 
ini_set("display_errors", "1");
error_reporting(-1);

$dir = dirname(__FILE__);

require_once "$dir/ot/ot.php";

ot::include_view('header', array('account' => null))
?>

// various stuff

<p>Please login below</p>
    <?php ot::include_view('login_form')?>

 

the ot.php file doesn't have any echo's or print_r's etc if that helps??

 

 

here's the header.php file..

<?php

 

if (ot::get('do_logout', 0) == 1) {
    ot::destroy_session();
    header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}");
    exit;
} elseif (self::post('do_reset_password')) {
    ot::do_reset_password($err);
    echo "$err";
}

$adb = ot::db('account');
$account = null;
$error = "";
$id = ot::account_id();
if ($id) {
    $account = ot::account_from('id', $id);

    $res = ot::do_change_password($account, $err);
    if ($res) {
        echo "<p>Password Changed Successfully</p>";
        $account = $res;
    } else if ($err) {
        echo "<p>Error: $err</p>";
    }

    $res = ot::do_change_email($account, $err);
    if ($res) {
        echo "<p>Email Changed Successfully</p>";
        $account = $res;
    } else if ($err) {
        echo "<p>Error: $res</p>";
    }

} else {
    $account = ot::do_login();
    if ($account) {
        header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}");
        exit;
    }
}
?>

 

here's the ot::do_login function

public static function do_login(&$err="")
{		
	$adb = ot::db('account');
	$e = self::post('email');
	$p = self::post('pwd', '', false);
	if (self::post('do_login') && $e && $p) {
		$ao = self::account_from('email', $e);
		if ($ao) {
			if (self::validate_login($e, $p, $ao)) {
				//echo "\n"."hit2";
				$_SESSION['id'] = $ao->id;
				return $ao;
			}
		}
		$err = "Invalid email or password";
		return false;
	}
}

 

and here's the login_form.php, which is called from ot::do_login from header.php ...

<form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' >
<p>Email:<br/><input type='text' name='email' /></p>
<p>Password:<br/><input type='password' name='pwd' /></p>
<p><input type='submit' name='do_login' value='Login' /> <input type='submit' name='do_reset_password' value='Reset Password' /></p>
</form>

 

 

Any pointers or useful things I've not posted?

 

is this bit of code from above ok? as in I'm doing some php stuff before the header() function gets used?

<html>
<head><title></title></head>
<body>
<?php 
ini_set("display_errors", "1");
error_reporting(-1);

$dir = dirname(__FILE__);

require_once "$dir/ot/ot.php";

ot::include_view('header', array('account' => null))

This is already the output(*):

<html>
<head><title></title></head>
<body>

After it you should not use header function. But you did as I see this code

ot::include_view('header', array('account' => null))

go after (*) and make some redirect

thanks guys, that's sorted it. I've moved the <html> tags down in the script

 

so I can understand this, even having the standard <html> <head><title> etc tags means that the php parser automaticaly sends a header back to the client browser

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.