How to resolve this error caused by plugin: Warning: Cannot modify header information****

Posted on 2009-02-21
Medium Priority
Last Modified: 2012-05-06
Alright, I've been beating my brains out trying to fix this one but it's not getting any better.

I'm working with someone on a plugin that will insert a social bookmarking menu into each wordpress post. It allows them to choose which sites they'd like to display, as well as whether to display the menu before or after each post.

The problem is, the plugin will activate fine. However, once it's activated nobody can comment without it throwing a mysql error:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\plugins\wp-social-bookmark-menu\wp-social-bookmark-menu.php:1) in C:\xampplite\htdocs\wordpress\wp-includes\pluggable.php on line 850

Now, even though it gives that error... It actually still posts the comment. Also, if you try to deactivate the plugin you get the same error, but if you refresh when you get the error it shows that the plugin has been deactivated.

I'm using Xampp and wordpress 2.7.1

I know that this error is most generally caused by excess whitespace betweeen php code blocks... but I can't find any extra space before or after the <? or ?>

I've attached the full code for the plugin below:
Plugin Name: wp social bookmark menu
Plugin URI: http://wordpress.org/extend/plugins/wp-social-bookmark-menu/
Description: Add a social bookmarking links. Thanks to <a target="_blank" href="http://eight7teen.com/about">eight7teen</a> for original ideaa and base code. See <a href="options-general.php?page=wp-social-bookmark-menu.php">configuration panel</a> for more settings. For more info and plugins visit <a href="http://labs.saidmade.com">Labs Saidmade</a>
Version: 1.0
Author: Giovambattista Fazioli
Author URI: http://www.undolog.com
//if(basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) die();
define('OPTIONSTITLE','Social Bookmark Menu');
define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
 * The default options are stored in this array (key => default value)
 * The global plugin variables have a $wpp_ prefix (wordpress plugin)
$wpp_options = array(
'position' => 'onthebottom','bookmark' => array('scriptstyle','blinklist','delicious','digg','furl','reddit','yahoomyweb','stumbleupon','technorati','mixx','myspace','designfloat','facebook')
 * Add to Wordpress options database
add_option(OPTIONSKEY, $wpp_options, OPTIONSTITLE);
 * re-Load options
$wpp_options = get_option(OPTIONSKEY);
// ________________________________________________________________________________________ OPTIONS
 * Add callback for adding options panel
function wpp_options_page() {
	if (function_exists('add_options_page')) {
		add_options_page(OPTIONSTITLE, OPTIONSTITLE, 8, basename(__FILE__), 'wpp_options_subpanel');
 * Draw Options Panel
function wpp_options_subpanel() {
	global $wpp_options, $_POST;
	$any_error = "";										// any error flag
	if(isset($_POST['flag_save'])) {						// have to save options
		$any_error = 'Your settings have been saved.';
		 * Check for any missing or wrong POST value
		if($_POST['position'] == '') {		
			$any_error = 'Some field is empty! Check and try again!';
			} else {
			$wpp_options['position'] = $_POST['position'];
			$wpp_options['bookmark'] = $_POST['bookmark'];
			update_option(OPTIONSKEY, $wpp_options);
	 * Show error or OK
	if($any_error != '') echo '<div id="message" class="updated fade"><p>'.$any_error.'</p></div>';
	 * You can include a separate file: include ('options.php');
?><div class="wrap">
    <h2>WP Social Bookmark Menu</h2>
	<form name="wp-social-bookmark-menu" id="wp-social-bookmark-menu" action="" method="post">
		<input type="hidden" name="flag_save" value="1" />
		  <table width="300" cellpadding="4" cellspacing="0">
		  <td align="right" valign="top" nowrap><label for="position">Position:</label> </td>
		  	  <input <?php echo (($wpp_options['position'] == "onthetop")? 'checked="checked"' : ""); ?> name="position" id="position" type="radio" value="onthetop" /> On the top<br/>
		  	  <input <?php echo (($wpp_options['position'] == "onthebottom")? 'checked="checked"' : ""); ?> name="position" id="position" type="radio" value="onthebottom" /> On the bottom
		   <td align="right" valign="top" nowrap><label for="position">Choose Bookmark:</label> </td>
		  	  <input <?php echo (@in_array("scriptstyle", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="scriptstyle" /> Script & Style <span class="scriptstyle"></span><br/>
			  <input <?php echo (@in_array("blinklist", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="blinklist" /> Blinklist <span class="blinklist"></span><br/>
			  <input <?php echo (@in_array("delicious", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="delicious" /> del.icio.us <span class="delicious"></span><br/>
			  <input <?php echo (@in_array("digg", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="digg" /> Digg this! <span class="digg"></span><br/>
			  <input <?php echo (@in_array("furl", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="furl" /> Furl <span class="furl"></span><br/>
			  <input <?php echo (@in_array("reddit", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="reddit" /> Reddit <span class="reddit"></span><br/>
			  <input <?php echo (@in_array("yahoomyweb", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="yahoomyweb" /> Yahoo MyWeb <span class="yahoomyweb"></span><br/>
			  <input <?php echo (@in_array("stumbleupon", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="stumbleupon" /> StumbleUpon <span class="stumbleupon"></span><br/>
			  <input <?php echo (@in_array("technorati", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="technorati" /> Technorati <span class="technorati"></span><br/>
			  <input <?php echo (@in_array("mixx", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="mixx" /> Mixx <span class="mixx"></span><br/>
			  <input <?php echo (@in_array("myspace", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="myspace" /> MySpace <span class="myspace"></span><br/>
			  <input <?php echo (@in_array("designfloat", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="designfloat" /> DesignFloat <span class="designfloat"></span><br/>
			  <input <?php echo (@in_array("facebook", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="facebook" /> Facebook <span class="facebook"></span><br/>
		  <td colspan="2"><div class="submit"><input type="submit" value="Save Settings" /></div></td>
	  	<p>Visit <a target="_blank" href="http://www.undolog.com">Undolog.com</a>, <a target="_blank" href="http://labs.saidmade.com">labs.saidmade.com</a> and <a target="_blank" href="http://www.saidmade.com"><img align="absmiddle" src="http://labs.saidmade.com/images/sm-a-80x15.png" border="0" /></a> for more information about author and WordPress Plugin</a>
 * Filter
function position_menu($content) {
	global $wpp_options;
	$title = get_the_title();
	$perma = get_permalink();
	$social = '<div class="wp-social-bookmark-menu"><ul class="socials">'.
	(in_array("scriptstyle", $wpp_options['bookmark'])?
	'<li class="script-style"><a href="http://scriptandstyle.com/submit?url='.$perma.'&title='.$title.'" title="Submit this to Script & Style"> </a></li>' : '').
	(in_array("blinklist", $wpp_options['bookmark'])?
	'<li class="blinklist"><a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&Url='.$perma.'&Title='.$title.'" title="Share this on Blinklist"> </a></li>' : '').
	(in_array("delicious", $wpp_options['bookmark'])?
	'<li class="delicious"><a href="http://del.icio.us/post?url='.$perma.'&title='.$title.'" title="Share this on del.icio.us"> </a></li>' : '').
	(in_array("digg", $wpp_options['bookmark'])?
	'<li class="digg"><a href="http://digg.com/submit?phase=2&url='.$perma.'&title='.$title.'" title="Digg this!"> </a></li>' : '').
	(in_array("furl", $wpp_options['bookmark'])?
	'<li class="furl"><a href="http://www.furl.net/storeIt.jsp?t='.$title.'&u='.$perma.'" title="Share this on Furl"> </a></li>' : '').
	(in_array("reddit", $wpp_options['bookmark'])?
	'<li class="reddit"><a href="http://reddit.com/submit?url='.$perma.'&title='.$title.'" title="Share this on Reddit"> </a></li>' : '').
	(in_array("yahoomyweb", $wpp_options['bookmark'])?
	'<li class="yahoo"><a href="http://myweb2.search.yahoo.com/myresults/bookmarklet?t='.$title.'&u='.$perma.'" title="Save this to Yahoo MyWeb"> </a></li>' : '').
	(in_array("stumbleupon", $wpp_options['bookmark'])?
	'<li class="stumble"><a href="http://www.stumbleupon.com/submit?url='.$perma.'&title='.$title.'" title="Stumble upon something good? Share it on StumbleUpon"> </a></li>' : '').
	(in_array("technorati", $wpp_options['bookmark'])?
	'<li class="technorati"><a href="http://technorati.com/faves?add='.$perma.'" title="Share this on Technorati"> </a></li>' : '').
	(in_array("mixx", $wpp_options['bookmark'])?
	'<li class="mixx"><a href="http://www.mixx.com/submit?page_url='.$perma.'&amp;title='.$title.'" title="Share this on Mixx"> </a></li>' : '').
	(in_array("myspace", $wpp_options['bookmark'])?
	'<li class="myspace"><a href="http://www.myspace.com/Modules/PostTo/Pages/?u='.$perma.'&amp;t='.$title.'" title="Post this to MySpace"> </a></li>' : '').
	(in_array("designfloat", $wpp_options['bookmark'])?
	'<li class="designfloat"><a href="http://www.designfloat.com/submit.php?url='.$perma.'&amp;title='.$title.'" title="Submit this to DesignFloat"> </a></li>' : '').
	(in_array("facebook", $wpp_options['bookmark'])?
	'<li class="facebook"><a href="http://www.facebook.com/share.php?u='.$perma.'&amp;t='.$title.'" title="Share this on Facebook"> </a></li>' : '').
	if($wpp_options['position'] == "onthetop") return $social.$content;
	else return $content.$social;
add_action('wp_head', 'add_styles');
function add_styles() {
	echo "\n".'<!-- Start Of Code Generated By WP-Social-Bookmark-Menu '.VERSION.' -->'."\n";
	if(@file_exists(TEMPLATEPATH.'/styles.css')) {
		wp_register_style('wp-social-bookmark-menu', get_stylesheet_directory_uri().'/styles.css', false, VERSION, 'all');
	} else {
		wp_register_style('wp-social-bookmark-menu', plugins_url('wp-social-bookmark-menu/styles.css'), false, VERSION, 'all');
	echo '<!-- End Of Code Generated By WP-Social-Bookmark-Menu '.VERSION.' -->'."\n";
function bookmark_styles() {
echo "<style type='text/css'>
form#wp-social-bookmark-menu span {
background:url(".WP_PLUGINS_PATH."sprite-trans.png) no-repeat;
span.scriptstyle { background-position:-400px bottom !important; }
span.mixx { background-position:-250px bottom !important; }
span.facebook { background-position:-450px bottom !important; }
span.flickr { background-position:-250px bottom !important; }
span.myspace { background-position:-200px bottom !important; }
span.blinklist { background-position:-600px bottom !important; }
span.yahoomyweb { background-position:-650px bottom !important; }
span.delicious { background-position:left bottom !important; }
span.stumbleupon { background-position:-50px bottom !important; }
span.reddit { background-position:-100px bottom !important; }
span.digg { background-position:-500px bottom !important; }
span.furl { background-position:-300px bottom !important; }
span.technorati { background-position:-700px bottom !important; }
span.designfloat { background-position:-550px bottom !important; }
add_action('admin_head', 'bookmark_styles');
add_action('admin_menu', 'wpp_options_page');
add_filter('the_content', 'position_menu');

Open in new window

Question by:blatantwaste
  • 2
  • 2

Author Comment

ID: 23702700
I just realized it would probably be more helpful just to post a zip folder with the entire plugin rather than just the php code portion, so you can download the plugin from here: http://eight7teen.com/uploads/wp-social-bookmark-menu.zip
LVL 39

Accepted Solution

Roger Baklund earned 2000 total points
ID: 23702832
Save the file as an ascii file, not as unicode/utf-8. It contains some "invisible" characters at the start.

$f = fopen('wp-social-bookmark-menu.php','r');
$data = fread($f,10);
  echo ord($data[$i]).' '.$data[$i].'<br />';


239 ï
187 »
191 ¿
60 <
63 ?
112 p
104 h
112 p
LVL 39

Expert Comment

by:Roger Baklund
ID: 23702857
These "invisible" characters are known as the BOM, it is normal that these exist in unicode encoded files.


EF BB BF == 239, 187, 191

Author Closing Comment

ID: 31549696
Not sure if ASCII is the same as ANSI, but my text editor didn't have an option for ASCII... So I saved it in ANSI format and it's working fine now. Thank you!

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install BuddyPress on your self-hosted WordPress site It’s been called everything from “social networking in a box” to “Facebook without the terms of service,” but until Feb. 16, BuddyPress was a relatively unknown outside the WordPress MU…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question