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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts

    Headers already sent?

    I have a php script whereby the user inputs their information and it gets submitted to the database.
    when it is submitted, I get this error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/.mala/tribalmaniac/theflashplace.com/top.php:16) in /home/.mala/tribalmaniac/theflashplace.com/myprofile.php on line 979

    top.php is this:

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" href="mainStyle.css" />
    <title>.:: The Flash Place ::.</title>
    <link rel="stylesheet" type="text/css" href="mainstylesheet.css" />
    <SCRIPT LANGUAGE="JavaScript">
    extensionArray = new Array(".jpg", ".png", ".gif");
    function LimitAttachImage(form, file) {
    allowSubmit = false;
    if (!file) return;
    while (file.indexOf("\\") != -1)
    file = file.slice(file.indexOf("\\") + 1);
    ext = file.slice(file.indexOf(".")).toLowerCase();
    for (var i = 0; i < extensionArray.length; i++) {
    if (extensionArray[i] == ext) { allowSubmit = true; break; }
    }
    if (allowSubmit) form.submit();
    else
    alert("Sorry, that file type is not allowed");
    }
    </script>
    		<link href="css/screen.css" rel="stylesheet" type="text/css" />
    		<script language="javascript" type="text/javascript" src="/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
    		<script language="javascript" type="text/javascript">
    tinyMCE.init({
    		mode : "specific_textareas",
    		editor_selector : "tinyMCE",
    		theme : "advanced",
    		plugins : "spellchecker,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable",
    		theme_advanced_buttons1_add_before : "save,newdocument,separator",
    		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
    		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,separator,forecolor,backcolor",
    		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
    		theme_advanced_buttons3_add_before : "tablecontrols,separator",
    		theme_advanced_buttons3_add : "emotions,iespell,flash,advhr,separator,print,separator,ltr,rtl,separator,fullscreen",
    		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,spellchecker",
    		theme_advanced_toolbar_location : "top",
    		theme_advanced_toolbar_align : "left",
    		theme_advanced_path_location : "bottom",
    		plugin_insertdate_dateFormat : "%d/%m/%Y",
    		plugin_insertdate_timeFormat : "%H:%M:%S",
    		extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
    		external_link_list_url : "example_data/example_link_list.js",
    		external_image_list_url : "example_data/example_image_list.js",
    		flash_external_list_url : "example_data/example_flash_list.js",
    		force_br_newlines : "true",
    		content_css : "style/content.css",
    		theme_advanced_resize_horizontal : false,
    		theme_advanced_resizing : true,
    		// file_browser_callback : "mcFileManager.filebrowserCallBack",
    		convert_urls : false,
    		dialog_type : "modal"
    });
    </script>
    
    </head>
    <body>
    <div id="main">
    <div id="banner">
    <img src="header.png" width="784" height="138" />
    </div>
    <div id="content">
    <div id="navpos">
    <p class="navtext">
    
    <?php
    include("connection.php");
    putenv("TZ=Europe/London");
    session_start();
    $id = $_SESSION['id'];
    $anynew = mysql_query("SELECT * FROM `message` WHERE `touser` = '$id' AND `read` = 0");
    $anynew_rows = mysql_num_rows($anynew);
    
    if(empty($_SESSION['id'])) {
        echo('<A HREF="index2.php">Home</A> | <A HREF="news.php">News</A> | <A HREF="tutorials.php">Tutorials</A> | <A HREF="forum.php">Forum</A> | <A HREF="gallery.php">Gallery</A> | <A HREF="myprofile.php">My Profile</A> | <A HREF="messages.php">My Messages</A> | <A HREF="register.php">Register</A>');
    }
    	
    else if(isset($_SESSION['id']))
    {
        echo('<A HREF="index2.php">Home</A> | <A HREF="news.php">News</A> | <A HREF="tutorials.php">Tutorials</A> | <A HREF="forum.php">Forum</A> | <A HREF="gallery.php">Gallery</A> | <A HREF="myprofile.php">My Profile</A> | <A HREF="messages.php">My Messages ('.$anynew_rows.' new)</A> | <A HREF="logout.php">Log Out</A>');
    }
    	
    ?>
    </p>
    </div>


    I've been told this problem is caused by whitespace, but i cant see where ive gone wrong?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    I think session_start() must be the very first thing on your .php page.
    Do all of the session stuff at the top, before anything else.

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    i moved all the session stuff to the top, but its made no difference?

    thing is on all the other headers on all the other pages except "myprofile" work just fine

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Try putting all of the php code at the very top of the page, and then ensure there is no whitespace before the first <?php tag. If that doesn't work then post on here the exact error message so we can better evaluate where the problem is coming from.

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Sorry I see you already have put the error message in there, stupid me!

    Have you sent any headers in the included file "connection.php" ?

    If you have then that would be your problem.

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    I put all the php at the top, and still the same error comes up, my connection page is just

    PHP Code:
    <?php
        $hostname 
    "***.theflashplace.com";
        
    $dbusername "***";
        
    $dbpassword "***";
        
    $database "***";

        
    $connection mysql_connect($hostname$dbusername$dbpassword) or die(mysql_error());
        
    mysql_select_db($database$connection) or die(mysql_error());
    ?>

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    The session_start() function can only be executed prior to anything being outputted to the web browser. The first thing in that file needs to be:

    PHP Code:
    <?php
    session_start
    ();
    ?>
    <html>
    <head>
    etc.
    If you have outputted anything to the browser at all including whitespace you will get that error.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    I did that, and checked for whitespace still the same problem

    It's driving me mad

  • #9
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Do you have any files specified in the auto_prepend setting that are getting included in every file?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #10
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    sorry, i dont think ive used 'auto_prepend' ?

  • #11
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    Hello there.

    No...this has nothing to do with session...though your session_start should always be at the top of your file.

    This error is usually generated when you have already used a header("Location: nextpage.php" ); function or any function that modifies the response header of a given request.

    to overcome this problem....create a .htaccess file and have the following lines written at the top of the file.

    PHP_FLAG output_buffering On
    php_value memory_limit "32M"

    If you cannot use .htaccess file...google search how you can set the above values using init_set() function...

    Good luck

  • #12
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    session_start sends headers 'under the hood', and editing .htaccess files isn't really necessary.

    it's probably worth posting the current state of your code as it's difficult to keep track of you saying "i've done that but it's still broken".

  • #13
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    the top.php is still the same but with the session_start at the top of the file
    I dont think it has anything to do with the top.php file because other files use the same page and also use headers and they all work fine.

    I have done this:

    PHP Code:
    if (($id == $id2) and ($admin == 1)){
    mysql_query("UPDATE members SET `displayname` = '$displayname' WHERE `id` = '$id'");
    $URL="myprofile.php?id=$id";
    header ("Location: $URL");
    }
    else if ((
    $id == $id2) and ($id == 7)){
    mysql_query("UPDATE members SET `displayname` = '$displayname' WHERE `id` = '$id'");
    $URL="myprofile.php?id=$id";
    header ("Location: $URL");
    }
    else if(
    $id == 7){
    $URL="myprofile.php?id=$id";
    header ("Location: $URL");
    }
    else if((
    $mod == 1) or ($admin == 1)){
    mysql_query("UPDATE members SET `displayname` = '$displayname' WHERE `id` = '$id'");
    $URL="myprofile.php?id=$id";
    header ("Location: $URL");
    }
    else if(
    $id == $id2){
    mysql_query("UPDATE members SET `displayname` = '$displayname' WHERE `id` = '$id'");
    $URL="myprofile.php?id=$id";
    header ("Location: $URL");
    }else{
    mysql_query("UPDATE members SET `displayname` = '$displayname' WHERE `id` = '$id'");
    $URL="myprofile.php?id=$id";
    header ("Location: $URL");

    I know most of the if statements arent necessary, but yeh thats the code im using that could be the problem?

  • #14
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    OK ...

    Step back and try a different approach ...

    Duplicate all of your suspect pages and then begin eliminating
    sections of the page until the error goes away. By eliminating,
    I mean remove some "includes", and/or sections of <?php ?>

    See if you can make most of the page render with the error and
    see what part(s) you removed that eliminated the error.

  • #15
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by ess View Post
    Hello there.

    No...this has nothing to do with session...though your session_start should always be at the top of your file.

    This error is usually generated when you have already used a header("Location: nextpage.php" ); function or any function that modifies the response header of a given request.

    to overcome this problem....create a .htaccess file and have the following lines written at the top of the file.

    PHP_FLAG output_buffering On
    php_value memory_limit "32M"

    If you cannot use .htaccess file...google search how you can set the above values using init_set() function...

    Good luck
    That is incorrect.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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