Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't stop outputting content to the browser before trying to send a header.

    I have an error is occurring because of an html webpage with a "php require" at the top of the page calling a script.

    Somehow I'm having a problem with sending content to the browser before I create a header. The result is.. when the script executes. I get an error.

    I'm a weak coder and this is driving me crazy. Everything I read is a bit complicated for me. please tolerate my "inability" I tend to need to be hand held.

    The error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/host/public_html/website.com/index.html:1) in /home/host/public_html/website.com/geoipscript.php on line 49


    The HTML page.

    Code:
    <?php require('geoipscript.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>the site</title>
    
    <link href="css/reset.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    </head>
    --------
    The script

    PHP Code:
    <?php
    /*
        April 4, 2009 - Script looks up the country code and state name of a visitor's IP address
        Visitors are given access depending on their geographic location
        
    */

    // VARIABLES
    $host='localhost';              //Enter your host here within the quotes
    $username='thename'//Enter your username of the mysql database
    $passwd='password2enter';     //Enter the password for that username
    $database='AAA1';    //This is where you database info is stored.
    $badurl='http://badurl.com';  // This is where you will be redirected if people are BAD
    $goodcountry = array('BE'); // Must be universal country code
    $goodregions = array('Bruxelles'); // Must be FULL name 


    // PROCESS
    function Dot2LongIP ($IPaddr) { 
        if (
    $IPaddr == "") {
            return 
    0;
        } else {
            
    $ips split ("\.""$IPaddr");
            return (
    $ips[3] + $ips[2] * 256 $ips[1] * 256 256 $ips[0] * 256 256 256);
        }
    }

    $db mysql_connect($host,$username,$passwd) or die ("mysql_connect() failed: " mysql_error());
    mysql_select_db($database,$db) or die ("mysql_select_db() failed: " mysql_error());
        
    $ip Dot2LongIP($_SERVER['REMOTE_ADDR']);
    $result = @mysql_query ("SELECT country_code, state_name FROM find_location WHERE '$ip' <= ip_to and '$ip' >= ip_from limit 1");
    while (
    $row = @mysql_fetch_array ($result)) {
        
    $country $row[0];
        
    $region $row[1];
    }

    if (
    $_GET['geo_debug']=="true") { // if degugging, just show what would happen
        
    echo "IP: ".$_SERVER['REMOTE_ADDR']."<br>Long: $ip<br>Country Code: $country<br>Region: $region<br>Allow? ";
        if (!
    in_array($country$goodcountry) && !in_array($region$goodregions)) {
            echo 
    "No";
        } else {
            echo 
    "Yes";
        }
    } else { 
    // if not debugging, redirect them if needed
        
    if (!in_array($country$goodcountry) && !in_array($region$goodregions)) {
            
    header("Location: $badurl");
            exit();
        } 
    }

    ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,011
    Thanks
    2
    Thanked 312 Times in 304 Posts
    Your index.html page has been saved with the UTF-8 BOM (Byte Order Mark) characters at the start of the file. You need to save it without the BOM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    Your index.html page has been saved with the UTF-8 BOM (Byte Order Mark) characters at the start of the file. You need to save it without the BOM.
    Problem solved !

    I do quick edits all the time on my sites using Notepad. Until recently, I never had a single problem. But yesterday, problems struck with vengence.

    I'm a real hack at any coding. Until a few hours ago, I never even heard of "UTF-8 BOM." I had no clue in the world there was "Invisable characters."

    So , I found and downloaded a programe called "Topstyle lite". And boom baby! My invisable characters showed up. I deleted them and everything came back online.


    Thank you very much for the help!

  • #4
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    I hope this won't be perceived as advertising, as it's not... If it is, mods, feel free to delete it.

    I use Eclipse / Aptana for most of my projects, but for "quick stuff" I use Programmers Notepad (a friend wrote it, so maybe I'm biased)

    http://www.pnotepad.org/

    No more notepad, no more BOM blues.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •