i get this Warning: Cannot modify header information - headers already sent by (output started at c:\appserv\www\conectarse.php:2) in c:\appserv\www\conectarse.php on line 61

and this warning happen in line 58 - header("Location: ".$MM_redirectLoginSuccess);
and in line 61 - header("Location: ".$MM_redirectLoginFailed);

pls i need somebody help me to resolve this

this is my code:

<?php 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";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
if (isset($_POST['login'])) {
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "/zonaprivada.php";
  $MM_redirectLoginFailed = "/existe.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);
<title>Documento sin t&iacute;tulo</title>
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  <input type="text" name="login" id="login">
    <input type="text" name="password" id="password">
    <input type="submit" name="conectar" id="conectar" value="Conectar">

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

8 Years
Discussion Span
Last Post by pzuurveen

Hi, dannynez

These kind of errors appear when you use the header function and has already been sending some kind of output to the browser for example this will not work:

echo ' ';
header('Location: index.php');

The problem is that any kind of output used before the header function will cause this kinds of problems.

You could for example try not splitting the PHP code into serveral blocks as you do on line 1, 2, 3, 27 and 28, try to use one complete block.

Best regards
// Xandro


Or even this error may occure if you are using white-space before <?php & after ?>.
Look for any statements that could send output to the user before this header statement. If you find one or more, find some way to move the header statement before them.


You can actually put the headers wherever you want.

Put ob_start() at the top of your page and then ob_end_flush() after your header()


To dddougal:

Yes this is a way to solve the problem, but it feels a little like going around the problem instead of writing good-practiced code.


alsso sent the headers
can't you use include or require ?

Edited by pzuurveen: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.