3

I am stuck with this error when trying to login to the admin panel. I can't get my head around it.

Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxx/public_html/wordpress/wp-config.php:1) in /home/xxxxxx/public_html/wordpress/wp-includes/pluggable.php on line 881

pluggable.php 881:

function wp_redirect($location, $status = 302) {
global $is_IIS;

$location = apply_filters('wp_redirect', $location, $status);
$status = apply_filters('wp_redirect_status', $status, $location);

if ( !$location ) // allows the wp_redirect filter to cancel a redirect
    return false;

$location = wp_sanitize_redirect($location);

if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
    status_header($status); // This causes problems on IIS and some FastCGI setups

header("Location: $location", true, $status);
}
endif;

I am using the latest version wordpress 3.4.2. My site seems to be working just fine but the error prevents me getting in to the login page which means I can't admin at all or uninstall the plugin (dbc backup 2) which seems to have triggered this problem. I have checked the wp.config file hunderds of times with HTML-kit tools and there is no visible whitespace at the begining nor at the end of the file. I have:

  1. Checked the whitespaces from wp-config file with HTML-Kit tools
  2. Downloaded and inserted new fresh wp-config file
  3. Disabled the plugins directory by renaming it

...and the error still remains

The only thing left for me to try is this code someone posted on wordpress forums claiming he had solved this problem by inserting the following code to the wp-config.php file:

    <?
//dont use header function in wordpress-wp_signup.php
global $domain;
global $path;
//change urlnew variable as per requirment
$urlnew = "http://".$domain.$path."/wp-admin/admin.php;

echo "<script>";
echo "location = '$urlnew';";
echo "</script>";
echo $urlnew;
?>

I am reluctant to add code as I am not familiar with html or php and I do not exactly understand how this code functions nor have detailed instructions where to place it exactly. Any better suggestions?


Themes function.php file ends like this, where should I exactly insert the code?:

// include custom widget

$temp_root = get_root_directory('include/plugin/custom-widget/custom-blog-widget.php');

include_once($temp_root . 'include/plugin/custom-widget/custom-blog-widget.php'); 

$temp_root = get_root_directory('include/plugin/custom-widget/custom-port-widget.php');

include_once($temp_root . 'include/plugin/custom-widget/custom-port-widget.php'); 

$temp_root = get_root_directory('include/plugin/custom-widget/custom-port-widget-2.php');

include_once($temp_root . 'include/plugin/custom-widget/custom-port-widget-2.php'); 

$temp_root = get_root_directory('include/plugin/custom-widget/popular-post-widget.php');

include_once($temp_root . 'include/plugin/custom-widget/popular-post-widget.php'); 

$temp_root = get_root_directory('include/plugin/custom-widget/contact-widget.php');

include_once($temp_root . 'include/plugin/custom-widget/contact-widget.php'); 

$temp_root = get_root_directory('include/plugin/custom-widget/flickr-widget.php');

include_once($temp_root . 'include/plugin/custom-widget/flickr-widget.php'); 

$temp_root = get_root_directory('include/plugin/custom-widget/twitter-widget.php');

include_once($temp_root . 'include/plugin/custom-widget/twitter-widget.php');



// get the path for the file ( to support child theme )

function get_root_directory( $path ){

    if( file_exists( STYLESHEETPATH . '/' . $path ) ){

        return STYLESHEETPATH . '/';

    }else{

        return TEMPLATEPATH . '/';

    }

}

?>
Kev
  • 118,037
  • 53
  • 300
  • 385
user1692154
  • 41
  • 1
  • 4
  • 1
    Remove the leading spaces before `` and it should work. – Gumbo Sep 23 '12 at 10:50
  • As I mentioned there is no leading spaces with notepad++ or HTML kit tools editor and saved in ANSI. To run aeven further with it, I even downloaded the file again and filled only the necessary parts. – user1692154 Sep 24 '12 at 01:12

3 Answers3

5

If you have functions.php file into your current theme directory, then do as below into your functions.php file

//allow redirection, even if your theme starts to send output to the browser
add_action('init', 'clean_output_buffer');
function clean_output_buffer() {
        ob_start();
}

HOW to remove BOM

In order to remove the BOM, Lafontaine suggests using the freeware utility XVI32, a free hexadecimal editor. The editor doesn’t install, you can just run the EXE file right from the ZIP. The process is simple – just drag your "affected" PHP file (in my case wp_config.php) into XVI32 and it will open in a neat byte-grid. Then, you should see that the very first three bytes in the file are "" followed by php tag.

If this is indeed the case, you should select each character in turn and just delete it (press the Del key). When you then save (Ctrl+S) the file, it will be completely the same as it used to be, only without the leading BOM.

Complete Article Link: http://blog.scribz.net/2010/12/windows-live-writer-wordpress-unicode-bom-error/

GBD
  • 15,847
  • 2
  • 46
  • 50
  • I couldnt get it to work. I have no experience in programing. Whre should I put it? – user1692154 Sep 24 '12 at 00:51
  • add my answer code just above function get_root_directory( $path ) this line into your function.php file – GBD Sep 24 '12 at 04:11
  • I edited the theme file with c-panels code editor in UTF-8. No luck. I am getting quite frustrated over this issue. I tried even disabling the theme and the plugins by temporarly renaming them as well as adding the basic wordpress theme twenty Eleven to a new theme directory but the error remains. I have no idea where to go from here. – user1692154 Sep 24 '12 at 10:26
  • can you paste your edited function.php file on codepad.org ? – GBD Sep 24 '12 at 10:41
  • After banging my head against the wall, I decided to open the config file in ansi (1983) and it looked something like this: ʼn»¿ – user1692154 Sep 24 '12 at 11:49
  • ... I can't thank you enough. After 15 hours of utter desperation finally got it fixed. notepad, notepad++ and html tool kit etc just couldnt spot it and Wordpress CODEX troubleshooting advices to use notepad to get rid of it... Mind boggling to say the least. – user1692154 Sep 24 '12 at 20:38
4

this is very common problem in wordpress, Add this :

<?php ob_start(); ?>

on top of the page. Happy coding!!

Gaurav
  • 638
  • 6
  • 18
  • no need to edit wp_config file . just put it on top of the page , where you write header("location: your_url"); – Gaurav Sep 24 '12 at 10:42
  • editing in wordpress core files is not a good thing at all. – Gaurav Sep 24 '12 at 10:43
  • I apologise for my ignorance but I have no experience in programming what so ever. Which page are you talking about exactly? That said, I opened the config file in ansi (1983) and it looked something like this: ʼn»¿ – user1692154 Sep 24 '12 at 11:45
  • in your wordpres theme folder ,you can see many files. here is the file (template file) which you include in your page. just put this line on very top of the file. another one, if you don't get anything, try to find header.php and place this line of code there. hope it make sense. – Gaurav Sep 24 '12 at 11:49
  • Found header.php file. Inserted the code on the first row above . No success. You dont think the characters showing when opening config file ansi are the real cause of this error and can be fixed swiftly? – user1692154 Sep 24 '12 at 12:16
  • one more thing, you can add javscript code for this if ob_start is not working. replace your header(location:abc.php) with this code: – Gaurav Oct 04 '12 at 06:51
  • This is a horrible suggestion. Why would you turn on output buffering at the top of every single page load? Your just wrapping his problem with duck tape. – Chris_O Jan 12 '13 at 18:06
0

This sounds similar to an issue I have had in other applications. Do you see the characters  anywhere in the page output? You might be having issues with byte order markers. http://en.wikipedia.org/wiki/Byte_order_mark These are dependent on the encoding of the file. I don't remember exactly how I addressed this issue but try saving the file in UTF-8? Or perhaps tell your web server somehow that the files are ANSI?

jcbwlkr
  • 7,789
  • 2
  • 22
  • 28
  • Hi Jacob and thanx for your reply. I haven't been able to detect any BOM/whitespaces. I have used HTML texk kit and notepad++ previously when transfering with Filezilla but now I use c-panel code editor in UTF-8. – user1692154 Sep 24 '12 at 10:09
  • Ok. I found the BOM when I opened the file in ANSI (1983). The problem remains however as the only thing visible to me is the BOM and couple of starting lines: `ʼn»¿ – user1692154 Sep 24 '12 at 10:52