oni-kun Posted December 4, 2009 Share Posted December 4, 2009 I a long time ago made a simple index for my site that includes the file via $_GET and a switch statement. This one script I have needs it to not be included for certain reasons but redirected. But it's not working.. Is having it nested, or having break; after it the problem?.. "Warning: Cannot modify header information - headers already sent by (output started at /xxxxx/public_html/index.php:1) in /xxxxx/public_html/index.php on line 54" ob_start is at the first position and my code is like this.. (the header() is near the bottom) <?php ob_start(); // Navi system. include('./logger.php'); //simple IP logging $server = $_SERVER['SERVER_NAME']; if (isset($_GET['page'])) { $page = $_GET['page']; if ($page == "") { require('http://'.$server.'/front.php'); } else { switch($page) { case 'home'; require('http://'.$server.'/front.php'); break; case 'contactus'; require('http://'.$server.'/contactus.php'); break; case 'games'; require('http://'.$server.'/games/games.php'); break; case 'downloadgames'; require('http://'.$server.'/games/downloadgames.php'); break; default; require('http://'.$server.'/404.php'); break; } } } else { if (isset($_GET['page']) && !isset($_GET['project'])) { include('http://'.$server.'/front.php'); } elseif (!isset($_GET['page']) && !isset($_GET['project'])) { //if neither are set include('http://'.$server.'/front.php'); } } //proj urls if (isset($_GET['project'])) { $page = $_GET['project']; if ($page == "") { require('http://'.$server.'/front.php'); } else { switch($page) { case 'translate'; require('http://'.$server.'/projects/translator.php'); break; case 'identify'; require('http://'.$server.'/projects/detection.php'); break; case 'trace'; header('Location: http://'.$server.'/projects/trace.php'); //The line with the error.. break; case 'whois'; require('http://'.$server.'/projects/whois_i.php'); break; default; require('http://'.$server.'/404.php'); break; } } } else { if (!isset($_GET['page']) && isset($_GET['project'])) { include('http://'.$server.'/front.php'); } else { //donothing, pass to proj. } } ?> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2009 Share Posted December 4, 2009 you probably have a white space or special character before your ob_start(); check your file format ? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 4, 2009 Author Share Posted December 4, 2009 you probably have a white space or special character before your ob_start(); check your file format ? I double checked. <?php ob_start(); ... At absolute beginning doesn't change it. My site went down to PHP 4.3 for some stupid reason maybe that is why.. Any other thoughts? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2009 Share Posted December 4, 2009 could be some server configuration settings not too sure, there is a output_buffering setting in php.ini I am not sure if this affects ob_start() though Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2009 Share Posted December 4, 2009 ob_start() should only be used if you intentionally want to buffer output. It should not be used to fix header errors. In your case it did not help did it? And frankly, we are tired of people attempting to use it to 'fix' header errors instead of finding the problem with their code and fixing their code. Your problem is that your file either contains characters in it before the opening <?php tag (in which case just check if there are any characters before the <?php tag and remove them) or your file has been saved as a UTF-8 encoded file and your editor has put the BOM (Byte Order Mark) characters at the start of the file (in which case, save your file as an ANSI encode file or save it as a UTF-8 encoded file without the BOM.) Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 4, 2009 Author Share Posted December 4, 2009 ob_start() should only be used if you intentionally want to buffer output. It should not be used to fix header errors. In your case it did not help did it? And frankly, we are tired of people attempting to use it to 'fix' header errors instead of finding the problem with their code and fixing their code. Your problem is that your file either contains characters in it before the opening <?php tag (in which case just check if there are any characters before the <?php tag and remove them) or your file has been saved as a UTF-8 encoded file and your editor has put the BOM (Byte Order Mark) characters at the start of the file (in which case, save your file as an ANSI encode file or save it as a UTF-8 encoded file without the BOM.) Oh man I never thought of that! I used a hex editor and found the BOM, I never put two and two together. Safe to say after deleting it, it worked! I think people use headers alot because they're not sure how to redirect? I'm sure not sure how to redirect to another page with PHP.. if it really is possible without output buffering.. Does the job. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.