Warning: Cannot modify header information - headers already sent by (output started a

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dannynez
    New Member
    • Sep 2010
    • 1

    Warning: Cannot modify header information - headers already sent by (output started a

    my problem is in line 58 - header("Locatio n: ".$MM_redirectL oginSuccess);
    and in line 61-header("Locatio n: ".$MM_redirectL oginFailed);

    i get this (Warning: Cannot modify header information - headers already sent by (output started a)

    my code is:

    Code:
    <? session_start();?>
    <?php virtual('/Connections/conexion.php');?>
    <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue ="", $theNotDefinedValue ="") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    ?>
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
      session_start();
    }
    $loginFormAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['accesscheck'])) {
      $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }
    if (isset($_POST['login'])) {
      $loginUsername=$_POST['login'];
      $password=$_POST['password'];
      $MM_fldUserAuthorization = "";
      $MM_redirectLoginSuccess = "/zonaprivada.php";
      $MM_redirectLoginFailed = "/incorrecto.php";
      $MM_redirecttoReferrer = false;
      mysql_select_db($database_conexion, $conexion);
      $LoginRS__query=sprintf("SELECT login, password FROM usuarios WHERE login=%s AND password=%s",
        GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
      $LoginRS = mysql_query($LoginRS__query, $conexion) or die(mysql_error());
      $loginFoundUser = mysql_num_rows($LoginRS);
      if ($loginFoundUser) {
         $loginStrGroup = "";
        //declare two session variables and assign them
        $_SESSION['MM_Username'] = $loginUsername;
        $_SESSION['MM_UserGroup'] = $loginStrGroup;	      
        if (isset($_SESSION['PrevUrl']) && false) {
          $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
        } 
        header("Location: ".$MM_redirectLoginSuccess);
    	}
      else {
        header("Location: ".$MM_redirectLoginFailed);
    	}
    }
    ?>
    <html>
    <head>
    <title>Documento sin t&iacute;tulo</title>
    </head>
    <body>
    <form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
      <label>Login
      <input type="text" name="login" id="login">
      </label>
      <p>
        <label>ContraseƱa
        <input type="text" name="password" id="password">
        </label>
      </p>
      <p>
        <label>
        <input type="submit" name="conectar" id="conectar" value="Conectar">
        </label>
      </p>
    </form>
    </body>
    </html>
    pls somebody can help me
    Last edited by Niheel; Sep 19 '10, 02:15 AM.
  • Rizladonovich
    New Member
    • Sep 2010
    • 13

    #2
    somewhere the script start to send data to user, before you get to redirect.

    You could:
    Do a flush + exit/die before the redirect(s), and look at source code of result page and see if there are anything before the error message. (not necessarily necessary with the flushing')

    It can also be useful to use wget with save header option: wget --save-headers some_address

    Also, take a look into buffering and ie

    function.ob-get-contents.php

    And
    1. Do you have short tags on? Your first opening is <? and not <?php
    2. Could be the fact that you use newline between the (several) opening and closing tags, - this would probably be sent by server.
    Last edited by Rizladonovich; Sep 19 '10, 04:10 AM. Reason: some notes

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      See this article for more information.

      Comment

      • oranoos3000
        New Member
        • Jan 2009
        • 107

        #4
        hi my friend
        header statement must be used befor other output is send to browser
        1- each space character or each tag that is set to browser
        before header statement cause to this statement doesnt work correctly
        note: in your code several time you close ?> and open this tag immediately this is unuseful and the other hand
        press enter in code create a \n that is white space for browser and can be caused this problem

        be successful

        Comment

        Working...