473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
3 1996
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
6,050 Expert 4TB
See this article for more information.
Sep 21 '10 #3
oranoos3000
107 100+
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

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

Similar topics

2
by: Phyzlo | last post by:
Hello, I've recently started learning PHP and have a question. I tried running below script which can be found at http://se2.php.net/manual/sv/function.setcookie.php but I keep getting this...
5
by: J Huntley Palmer | last post by:
I am getting this error: Cannot modify header information - headers already sent by when I issue a header ("Location: http://www.foobar.com"); How can I redirect the user to such a site...
5
by: half21back | last post by:
Can anyone tell me what is wrong with this code? <?php if (isset($_COOKIE)) { $url = $row_rsCookieReferral; header("Location: $url"); } ?>
2
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
3
by: TechnoAtif | last post by:
Hi All. I have got problem with the header. If i run my php script in the local host it runs perfectly but if i do the same on net after loading it via ftp. it gives following error: The code...
5
by: mukeshrasm | last post by:
Hi I am working on gd library with PHP to create graphs which is displaying correctly. But I want to display some information about this graph as text which will not be part of this graph means...
2
by: pks83 | last post by:
Hello I am also facing this problem when i amtrying to send additional header information. Warning: Cannot modify header information - headers already sent by (output started at header.php:96)...
2
by: creative1 | last post by:
I get following error on page : Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\desiorb\411.php:9) in C:\xampp\htdocs\desiorb\411.php on line 21 when...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.