Hi all,
I’ve been scratching my head and searching the web for answers to this problem for a couple of days now and would really appreciate any available help in solving it.
My problem is identical to beachjester’s, but changing my editor and the encoding did not fix it for me.
I am receiving the message:
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php:8) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 59
Here is the full code of my controller file:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
<title>ijdb Controller</title>
</head>
<body>
<?php
if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map(‘stripslashes_deep’, $value) :
stripslashes($value);
return $value;
}
$_POST = array_map(‘stripslashes_deep’, $_POST);
$_GET = array_map(‘stripslashes_deep’, $_GET);
$_COOKIE = array_map(‘stripslashes_deep’, $_COOKIE);
$_REQUEST = array_map(‘stripslashes_deep’, $_REQUEST);
}
if (isset($_GET[‘addjoke’]))
{
include ‘addJokeForm.html.php’;
exit();
}
$link = mysqli_connect(‘localhost’, ‘root’, ‘password’);
if (!$link)
{
$error = ‘Unable to connect to the database server.’;
include ‘error.html.php’;
exit();
}
if (!mysqli_set_charset($link, ‘utf8’))
{
$error = ‘Unable to set database connection encoding.’;
include ‘error.html.php’;
exit();
}
if (!mysqli_select_db($link, ‘ijdb’))
{
$error = ‘Unable to locate the joke database.’;
include ‘error.html.php’;
exit();
}
if (isset($_POST[‘joketext’]))
{
$joketext = mysqli_real_escape_string($link, $_POST[‘joketext’]);
$sql = ‘INSERT INTO joke SET
joketext="’ . $joketext . ‘",
jokedate=CURDATE()’;
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted joke: ’ . mysqli_error($link);
include ‘error.html.php’;
exit();
}
header(‘Location: .’);
exit();
}
$result = mysqli_query($link, ‘SELECT joketext FROM joke’);
if (!$result)
{
$error = 'Error fetching jokes: ’ . mysqli_error($link);
include ‘error.html.php’;
exit();
}
while ($row = mysqli_fetch_array($result))
{
$jokes = $row[‘joketext’];
}
include ‘jokes.html.php’;
?>
</body>
</html>
Diagnosis so far:
Have searched high and low through this file, along with all of the associated include files for whitespace, and have stripped out anything that looks even remotely like whitespace.
Have edited the scripting files with Dreamweaver, TextEdit and Notepad++, changing the encoding type from ANSI to UTF8 without BOM, with no change.
Have tested the index.php file for a BOM signature using the w3.org tester. No BOM found.
The code referenced by the “…\connect\index.php:8” part of the error message is where my php starts, i.e. “<?php” is located on line 8.
The code referenced by the “…\connect\index.php on line 59” part of the error message is where the header function is called, i.e. “header(‘Location: .’);” is found on line 59.
Can anyone think of anything else I can try?
Many thanks.