Bienvenido a datoweb.com!! En este foro podrás encontrar ayuda sobre diseño y desarrollo web en general. Si quieres formar parte de esta comunidad para pedir ayuda o colaborar ayudando a otros usuarios del foro solo tienes que registrarte desde el siguiente enlace: Registrarse en el Foro

Error al iniciar sesión Cannot modify header

acabo de agregarle un sistema de logeo pop up a mi pagina www.mtbeat.com el usuario es demo y la contraseña es demo pero a la hora que entro parece que hay un error algo del header el archivo de este esta de la siguiente forma:
<?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['nombre'])) {
  $loginUsername=$_POST['nombre'];
  $password=md5($_POST['password']);
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../index.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conexion, $conexion);
  
  $LoginRS__query=sprintf("SELECT nombre, password, estado, id FROM m_users WHERE nombre=%s AND password=%s AND estado=1",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $conexion) or die(mysql_error());
  $miIdUsuario = mysql_fetch_assoc($LoginRS);
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;
	$_SESSION['MM_Id'] = $miIdUsuario ["id"];

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO m_users (nombre, email, password, estado, avatar) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString(md5($_POST['password']), "text"),
                       GetSQLValueString($_POST['estado'], "int"),
                       GetSQLValueString($_POST['avatar'], "text"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

  $insertGoTo = "../index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!----    POPUP #1    ----->  
<a href="#x" class="overlay" id="login_form"></a>
<div class="box">
	<h2>LOG IN</h2>
<!--    Start "join with facebook" and "twitter", you can delete if you don't like it -->
	<div class="connectwith">
		<input class="fb" type="button"  value="Join with Facebook" />
        <input class="tw" type="button"  value="Join with Twitter" />
	</div>
<!-- end of "join with facebook" and "twitter"  -->
	<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
       <input type="text" class="text-field" name="nombre" id="nombre" placeholder="Username" />
       	<input type="password" class="text-field" name="password" id="password" placeholder="Password" />
       	<div id="buttons">  <input type="submit" name="button" id="button" value="Login" class="red"/>
		<a href="#signup_form"><input type="button" value="Sign up" class="blue"/></a></div>
		<p><input type="checkbox" > <label>Remember me</label></p>
        <p><a id="forg" href="#recover">Forgot Your Password?</a></p></br>
	</form>
    	<a class="close" href="#close"></a>
<!-- error state it is not visible because: visibility:hidden -->
   <div class="error">
   <div class="errortext">Incorrect login or password</div>
   </div>
<!--end of error state -->
  
</div>
<!----- END OF POPUP #1  ----->
<!----    POPUP #2    ----->  
<a href="#x" class="overlay" id="signup_form"></a>
<div class="box">

	<h2>SIGN UP</h2>
    <!--    Start "join with facebook" and "twitter", you can delete if you don't like it -->
	<div class="connectwith">
		<input class="fb" type="button"  value="Join with Facebook" />
        <input class="tw" type="button"  value="Join with Twitter" />
	</div> 
    <!-- end of "join with facebook" and "twitter"  -->
	<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
    	<input type="text" class="text-field" name="nombre" placeholder="username" />
    	<input type="email" class="text-field" name="email" placeholder="email" />
    	<input type="password" class="text-field" name="password" placeholder="Password" />
		<p><input type="checkbox"><label>I agree <a href="#">terms and conditions</a></label></p></br></br>
    	<input type="submit" value="Registrarme" class="blue-round"/></br>
    	<p>Already have account? <a href="#login_form">Log In</a></p>
	</form>
        <a class="close" href="#close"></a>

</div> 
<!----- END OF POPUP #2  ----->
<!----    PASSWORD RECOVERY    ----->  
<a href="#x" class="overlay" id="recover"></a>
<div class="box">
 
	<h2>Forgot your password?</h2>
    <p>We’ll email a code to this address.</p>
	<br>
	<br>
    	<input type="text" class="text-field" placeholder="email" />
    	<input type="button" value="Send" class="blue-round"/>
        <a class="close" href="#close"></a>

</div> 
<!----- PASSWORD RECOVERY  ----->
Alguna idea para que funcione bien mi nuevo sistema de logeo?
0
Puntos
1559
Visitas
3
Resp
Por miguelsirna hace 128 meses
Principiante
Respuesta #1
crea un archivo php por ejemplo process.php y te llevas de aquí todo el código que inserta el registro:
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO m_users (nombre, email, password, estado, avatar) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString(md5($_POST['password']), "text"),
                       GetSQLValueString($_POST['estado'], "int"),
                       GetSQLValueString($_POST['avatar'], "text"));

  mysql_select_db($database_conexion, $conexion);
  $Result1 = mysql_query($insertSQL, $conexion) or die(mysql_error());

  $insertGoTo = "../index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
después en el action del form le dices que envíe los datos a ese nuevo archivo y los procese:
<form id="form1" name="form1" method="POST" action="process.php">
de esa forma no tienes dos scrips mezclados por eso suelen ser los Warning: Cannot modify header information
0
Puntos
Por alber hace 128 meses
Administrador
Respuesta #2
claro ten en cuenta que ahora mismo tienes 2 headers en la misma pagina por eso te tira el error
0
Puntos
Por zeuskx hace 128 meses
Administrador Sitio web
Respuesta #3
Ya funciona a la perfeccion :D
0
Puntos
Por miguelsirna hace 128 meses
Principiante
Compartir en facebook
Compartir en twitter
Compartir
Para comentar Inicia sesión o Registrate