423,850 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,850 IT Pros & Developers. It's quick & easy.

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

P: 1
my problem is in line 58 - header("Location: ".$MM_redirectLoginSuccess);
and in line 61-header("Location: ".$MM_redirectLoginFailed);

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

my code is:

Expand|Select|Wrap|Line Numbers
  1. <? session_start();?>
  2. <?php virtual('/Connections/conexion.php');?>
  3. <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue ="", $theNotDefinedValue ="") 
  4. {
  5.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  6.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  7.   switch ($theType) {
  8.     case "text":
  9.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  10.       break;    
  11.     case "long":
  12.     case "int":
  13.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  14.       break;
  15.     case "double":
  16.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  17.       break;
  18.     case "date":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;
  21.     case "defined":
  22.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  23.       break;
  24.   }
  25.   return $theValue;
  26. }
  27. }
  28. ?>
  29. <?php
  30. // *** Validate request to login to this site.
  31. if (!isset($_SESSION)) {
  32.   session_start();
  33. }
  34. $loginFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_GET['accesscheck'])) {
  36.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  37. }
  38. if (isset($_POST['login'])) {
  39.   $loginUsername=$_POST['login'];
  40.   $password=$_POST['password'];
  41.   $MM_fldUserAuthorization = "";
  42.   $MM_redirectLoginSuccess = "/zonaprivada.php";
  43.   $MM_redirectLoginFailed = "/incorrecto.php";
  44.   $MM_redirecttoReferrer = false;
  45.   mysql_select_db($database_conexion, $conexion);
  46.   $LoginRS__query=sprintf("SELECT login, password FROM usuarios WHERE login=%s AND password=%s",
  47.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
  48.   $LoginRS = mysql_query($LoginRS__query, $conexion) or die(mysql_error());
  49.   $loginFoundUser = mysql_num_rows($LoginRS);
  50.   if ($loginFoundUser) {
  51.      $loginStrGroup = "";
  52.     //declare two session variables and assign them
  53.     $_SESSION['MM_Username'] = $loginUsername;
  54.     $_SESSION['MM_UserGroup'] = $loginStrGroup;          
  55.     if (isset($_SESSION['PrevUrl']) && false) {
  56.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
  57.     } 
  58.     header("Location: ".$MM_redirectLoginSuccess);
  59.     }
  60.   else {
  61.     header("Location: ".$MM_redirectLoginFailed);
  62.     }
  63. }
  64. ?>
  65. <html>
  66. <head>
  67. <title>Documento sin t&iacute;tulo</title>
  68. </head>
  69. <body>
  70. <form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  71.   <label>Login
  72.   <input type="text" name="login" id="login">
  73.   </label>
  74.   <p>
  75.     <label>Contraseña
  76.     <input type="text" name="password" id="password">
  77.     </label>
  78.   </p>
  79.   <p>
  80.     <label>
  81.     <input type="submit" name="conectar" id="conectar" value="Conectar">
  82.     </label>
  83.   </p>
  84. </form>
  85. </body>
  86. </html>
  87.  
pls somebody can help me
Sep 19 '10 #1
Share this Question
Share on Google+
3 Replies


P: 13
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.
Sep 19 '10 #2

Markus
Expert 5K+
P: 6,050
See this article for more information.
Sep 21 '10 #3

oranoos3000
100+
P: 107
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
Sep 21 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.