What is wrong with this code?

Discussion in 'PHP' started by adacprogramming, Jul 24, 2007.

  1. #1
    I'm trying to do a php 301 redirect. this is the entire html I am using.
    I keep getting
    Warning: Cannot modify header information - headers already sent by (output started at /home/content/D/w/a/DwayneAMG/html/eurekaclassifieds/index.php:4) in /home/content/D/w/a/DwayneAMG/html/eurekaclassifieds/index.php on line 5

    Any ideas?:confused:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <?php // Permanent redirection
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://classifieds.norcalcars.com/");
    exit();
    ?>
    </head>
    <body>
    </body>
    </html>
    
    PHP:

     
    adacprogramming, Jul 24, 2007 IP
  2. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You can't have any output before the Location header is sent, meaning you can't send anything to the browser before the header() call like you are doing.

    Will work:

    
    <?php // Permanent redirection
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://classifieds.norcalcars.com/");
    exit();
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    
    PHP:
     
    mrmonster, Jul 24, 2007 IP
  3. adacprogramming

    adacprogramming Well-Known Member

    Messages:
    1,615
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Thanks
    I've been trying to use NVU as my editor. It wouldn't allow this. Edited it in textpad and that worked

    Thanks Again.

     
    adacprogramming, Jul 24, 2007 IP