Jump to content

[SOLVED] Cannot modify header information - headers already sent... HELP NEEDED!!!


dennismonsewicz

Recommended Posts

Here is my code:

 

<?php

require "includes/sql.php";

$action = $_GET['action'];

if($_POST) {

	if($_POST['username'] || $_POST['password']) {
		$_SESSION['username'] = stripslashes($_POST['username']);
		$_SESSION['password'] = stripslashes($_POST['password']);
	}

}


switch($action) {

	case "login":
		$result = mysql_query("SELECT * FROM users where username = '".mysql_real_escape_string($_SESSION['username'])."' AND password = '".mysql_real_escape_string($_SESSION['password'])."'") or die(mysql_error());
		$num_rows = mysql_num_rows($result);
		header("location:index.php");
	exit;
	break;

	case "logout":
		session_destroy();
		header("location:index.php");
	exit;
	break;	
}

$login = '<a class="title">Login</a>
			<div>
				<form action="index.php?action=login" method="post">
					<label>Username:</label> <input type="text" name="username" id="username" />
					<label>Password: </label> <input type="password" name="password" id="password" />
					<input type="image" src="images/login.jpg" id="submit" />
				</form>
			</div>';

$logout = '<a class="title">My Profile</a>
                <div>
                    <ul>
                    	<li><a href="changepw.php">Change Password</a></li>
                        <li><a href="change-email.php">Change Email Address</a></li>
                        <li><a href="devotionals.php">Devotionals I wrote</a></li>
                        <li><a href="index.php?action=logout">Logout</a></li>
                    </ul>
                </div>
                <a class="title">Tools</a>
                <div>
                    <ul>
                    	<li><a href="#">Testing</a></li>
                    </ul>
                </div>
                <a class="title">Devotionals</a>
                <div>
                    <ul>
                    	<li><a href="#">Testing</a></li>
                    </ul>
		</div>
            
            <a class="title">Topics</a>
                <div>
                   <ul>
                    	<li><a href="#">Testing</a></li>
                    </ul>
		</div>';

?>

	<div class="accordion">
            	<?php if(!$_SESSION)
					{
						echo $login;
					} else {
						echo $logout;
					}
			?>

            </div> <!-- CLOSES ACCORDION DIV -->

 

Anyone got any ideas? This file is included in the header.php file, in which the header.php is included in the index.php file.

Link to comment
Share on other sites

The problem is that somewhere in your file there is something being sent to the browser before some kind of redirection.

 

Try putting ob_start(); at ht ebeginning of the file and

ob_end_flush(); at the end.

 

Should cure it.

 

Keith

Link to comment
Share on other sites

The error message states which file and line number the output is being started at that is preventing the headers from working. Reading the error message will tell you where in your code you need to look to start troubleshooting the problem.

Link to comment
Share on other sites

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.