junkybrewster
12-26-2007, 08:58 PM
Hi All :)
I am running a rich text editor on my webpage using a (heavily) modified version of abitwhizzy/whizzywig. It works perfectly on my midPhase hosting package but here on bluehost, when I make my changes in the editor and click save, I get the following warning:
Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/.../editor.html:7) in /home/public_html/.../abitwhizzy.php on line 52.
I have searched for that problem but a) didn't understand all the answers and b) I've tried what people seemed to suggest and I'm still broken hehe.
I am using include files to allow user to edit only a section of a page. The include files are still updated/saved, it's just my editor page will not redirect back to where it is supposed to (line 52 - header: "location...).
I have removed everything I think is whitespace from any tags.. I did have editor.html under a login screen, but I removed my set sessions include file to test, and I still get the error. I've gone through the php file looking for whitespace or anything that would send html to the browser before the header location call... but I just can't see it.
Now, editor.html is just a plain html page, with my call to include the editor in the middle of the page <?php include("abitwhizzy.php")?> (oh yeah, I allowed html parsing of php in .htaccess). It really needs to go there, because that's where the editor will render! I can't see how I could have it anywhere else. Again, works fine at midPhase.
What confuses me more is the error message referring to editor.html:7. Does that mean line 7? If so, that is my <title> tag.
I am on PHP 4 here. I even converted over to PHP 5 in the settings (as midphase is 5.2.4) but that didn't do anything.
Here is the code I am using in abitwhizzy.php:
<?
//abitwhizzy.php - whizzywig web page editor, demonstrating whizzywig.js
//Copyright 2005, John Goodman - john.goodman(at)unverse.net (i removed some of the comments here for ease of reading)
if (!isset($_SERVER))
{
$_GET = &$HTTP_GET_VARS;
$_POST = &$HTTP_POST_VARS;
$_ENV = &$HTTP_ENV_VARS;
$_SERVER = &$HTTP_SERVER_VARS;
$_COOKIE = &$HTTP_COOKIE_VARS;
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
}
$f = $_REQUEST['f'];
$t = $_REQUEST['t'];
//CONFIGURE HERE ================================================== ==================
if (!$password) $password= ""; //can leave password as "" if you are using .htaccess to protect abitwhizzy
if (!$whizzywig) $whizzywig = "whizzery/whizzywig.js"; //path to whizzywig.js required
if (!$cssFile) $cssFile= "css/editor.css"; //choose your stylesheet, or set to ""
if (!$buttonPath) $buttonPath = "whizzery/buttons/"; //toolbar images live here. "" for text buttons
if (!$imageBrowse) $imageBrowse = ""; // "" for no image browser
if (!$linkBrowse) $linkBrowse = ""; // "" for no link browser
if (!$toolbar) $toolbar = "bold italic underline left center right bullet number"; //try "all" if you need more
if (!$editarea) $editarea = "width:90%; height:250px";
if (!$xhtml) $xhtml = "whizzery/xhtml.js"; //path to xhtml converter, or set to "" for HTML 4.01. Use appropriate header in $top.
if (!$extensions) $extensions = "/(html)$/"; //file extensions to consider for edit (in the brackets|to separate)
//LEAVE THESE
if ($xhtml) $doctype = '<!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" xml:lang="en" lang="en">';
else $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>';
//HTML TEMPLATE: Use these 2 variables ($top and $tail) to wrap the generated HTML in your own template.
if (!$top) $top = "";
if (!$tail) $tail = "";
//END CONFIG ================================================== ======================
if (preg_match("#^\.|\.\.\/|^\/#",$f)) die ("Not allowed!");
if ($_REQUEST['save']) { //write page and go there
if ($_REQUEST['p'] != $password) die ("<h1>Wrong password: not saved.</h1>Click the Back button to try again. ");
$edited = $_REQUEST['edited'];
if ($f == "top.shtml" || $f == "tail.shtml") $html = stripslashes($edited);
else {
$html = $top."";
$html .= stripslashes($edited);
$html .= "".$tail;
}
$fsave = fopen($f, 'w'); //save the edited file
fwrite($fsave, $html);
fclose($fsave);
header("Location: editlinks.html");
} else if (file_exists($f)) {
$fedit = fopen($f, 'r'); //open the file for edit
$content = fread($fedit, filesize($f));
$start = strpos($content,"<!--#include virtual='top.shtml'-->") ? "/.*<!--#include virtual='top.shtml'-->/" : "|.*<body[^>]*>|iU";
$stop = strpos($content,"<!--#include virtual='tail.shtml'-->") ? "/<!--#include virtual='tail.shtml'-->.*/" : "|</body>.*$|iU";
$content = preg_replace($start,'',$content);
$content = preg_replace($stop,'',$content);
fclose($fedit);
preg_match('|<title>(.*)</title>|i',$content, $match);
$t = $match[1]; //grab the title
}
?>
I even tried adding php to the opening <? tag of that script above (NB: I left out the second part of the script, the one that renders the form for the editor.. I didn't think it relevant). I also tried deleting all the comments too in case of whitespace...
Do you think my editlinks page could do it? This is still under login. This parses the include file name into the editor (and opens the editor). This is also where I want to redirect to after save.. anyway, basically I don't know what I'm talking about in this area hehe.
Happy holidays! - Junky
I am running a rich text editor on my webpage using a (heavily) modified version of abitwhizzy/whizzywig. It works perfectly on my midPhase hosting package but here on bluehost, when I make my changes in the editor and click save, I get the following warning:
Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/.../editor.html:7) in /home/public_html/.../abitwhizzy.php on line 52.
I have searched for that problem but a) didn't understand all the answers and b) I've tried what people seemed to suggest and I'm still broken hehe.
I am using include files to allow user to edit only a section of a page. The include files are still updated/saved, it's just my editor page will not redirect back to where it is supposed to (line 52 - header: "location...).
I have removed everything I think is whitespace from any tags.. I did have editor.html under a login screen, but I removed my set sessions include file to test, and I still get the error. I've gone through the php file looking for whitespace or anything that would send html to the browser before the header location call... but I just can't see it.
Now, editor.html is just a plain html page, with my call to include the editor in the middle of the page <?php include("abitwhizzy.php")?> (oh yeah, I allowed html parsing of php in .htaccess). It really needs to go there, because that's where the editor will render! I can't see how I could have it anywhere else. Again, works fine at midPhase.
What confuses me more is the error message referring to editor.html:7. Does that mean line 7? If so, that is my <title> tag.
I am on PHP 4 here. I even converted over to PHP 5 in the settings (as midphase is 5.2.4) but that didn't do anything.
Here is the code I am using in abitwhizzy.php:
<?
//abitwhizzy.php - whizzywig web page editor, demonstrating whizzywig.js
//Copyright 2005, John Goodman - john.goodman(at)unverse.net (i removed some of the comments here for ease of reading)
if (!isset($_SERVER))
{
$_GET = &$HTTP_GET_VARS;
$_POST = &$HTTP_POST_VARS;
$_ENV = &$HTTP_ENV_VARS;
$_SERVER = &$HTTP_SERVER_VARS;
$_COOKIE = &$HTTP_COOKIE_VARS;
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
}
$f = $_REQUEST['f'];
$t = $_REQUEST['t'];
//CONFIGURE HERE ================================================== ==================
if (!$password) $password= ""; //can leave password as "" if you are using .htaccess to protect abitwhizzy
if (!$whizzywig) $whizzywig = "whizzery/whizzywig.js"; //path to whizzywig.js required
if (!$cssFile) $cssFile= "css/editor.css"; //choose your stylesheet, or set to ""
if (!$buttonPath) $buttonPath = "whizzery/buttons/"; //toolbar images live here. "" for text buttons
if (!$imageBrowse) $imageBrowse = ""; // "" for no image browser
if (!$linkBrowse) $linkBrowse = ""; // "" for no link browser
if (!$toolbar) $toolbar = "bold italic underline left center right bullet number"; //try "all" if you need more
if (!$editarea) $editarea = "width:90%; height:250px";
if (!$xhtml) $xhtml = "whizzery/xhtml.js"; //path to xhtml converter, or set to "" for HTML 4.01. Use appropriate header in $top.
if (!$extensions) $extensions = "/(html)$/"; //file extensions to consider for edit (in the brackets|to separate)
//LEAVE THESE
if ($xhtml) $doctype = '<!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" xml:lang="en" lang="en">';
else $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>';
//HTML TEMPLATE: Use these 2 variables ($top and $tail) to wrap the generated HTML in your own template.
if (!$top) $top = "";
if (!$tail) $tail = "";
//END CONFIG ================================================== ======================
if (preg_match("#^\.|\.\.\/|^\/#",$f)) die ("Not allowed!");
if ($_REQUEST['save']) { //write page and go there
if ($_REQUEST['p'] != $password) die ("<h1>Wrong password: not saved.</h1>Click the Back button to try again. ");
$edited = $_REQUEST['edited'];
if ($f == "top.shtml" || $f == "tail.shtml") $html = stripslashes($edited);
else {
$html = $top."";
$html .= stripslashes($edited);
$html .= "".$tail;
}
$fsave = fopen($f, 'w'); //save the edited file
fwrite($fsave, $html);
fclose($fsave);
header("Location: editlinks.html");
} else if (file_exists($f)) {
$fedit = fopen($f, 'r'); //open the file for edit
$content = fread($fedit, filesize($f));
$start = strpos($content,"<!--#include virtual='top.shtml'-->") ? "/.*<!--#include virtual='top.shtml'-->/" : "|.*<body[^>]*>|iU";
$stop = strpos($content,"<!--#include virtual='tail.shtml'-->") ? "/<!--#include virtual='tail.shtml'-->.*/" : "|</body>.*$|iU";
$content = preg_replace($start,'',$content);
$content = preg_replace($stop,'',$content);
fclose($fedit);
preg_match('|<title>(.*)</title>|i',$content, $match);
$t = $match[1]; //grab the title
}
?>
I even tried adding php to the opening <? tag of that script above (NB: I left out the second part of the script, the one that renders the form for the editor.. I didn't think it relevant). I also tried deleting all the comments too in case of whitespace...
Do you think my editlinks page could do it? This is still under login. This parses the include file name into the editor (and opens the editor). This is also where I want to redirect to after save.. anyway, basically I don't know what I'm talking about in this area hehe.
Happy holidays! - Junky