Foros del Web » Programando para Internet » PHP »

Warning: session_start() [function.session-start]: Cannot send session cache limiter

Estas en el tema de Warning: session_start() [function.session-start]: Cannot send session cache limiter en el foro de PHP en Foros del Web. Hola a todos, me estoy volviendo loco con esto... Me está apareciendo el siguiente error cuando entro a td_addconsulta.php: Warning: session_start() [function.session-start]: Cannot send session ...
  #1 (permalink)  
Antiguo 26/03/2009, 13:18
Avatar de chiquirf  
Fecha de Ingreso: noviembre-2005
Ubicación: Madrid
Mensajes: 215
Antigüedad: 18 años, 5 meses
Puntos: 3
Warning: session_start() [function.session-start]: Cannot send session cache limiter

Hola a todos, me estoy volviendo loco con esto...

Me está apareciendo el siguiente error cuando entro a td_addconsulta.php:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/instalal/public_html/miweb/principal/clubSHA/talkdoctor/td_addconsulta.php:1) in /home/instalal/public_html/miweb/principal/clubSHA/cods/validar_sesion_1.php on line 4

Se que no se debe lanzar al navegador ningún html antes del session_start(), incluyendo los caracteres en blanco; esto ya lo sabía porque antes me pasó lo mismo y era por esto.

Lo que me raya ahora es que este error me aparece SOLO CON UNO de los php de la web, CON NINGUN OTRO MAS...!!!! y todos tienen los mismos require_once() al comienzo.

no voy a poner todo el td_addconsulta.php (php + html), pero si les pongo toda la parte de php para ver si detectan un fallo, porque yo no...

Código PHP:
<?php 

require_once('../cods/validar_sesion_1.php'); 
require_once(
'../cods/sha_clubsha.php'); 
require_once(
'../cods/funciones.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;
}
}

// HASTA AQUI TODOS MIS PHP SON IGUALES

$id_med "";
if (isset(
$_GET['id_med'])) {
  
$id_med $_GET['id_med'];
}

$fail 0;
if (isset(
$_GET['fail'])) {
  
$fail $_GET['fail'];
}



$lang "en";
if (isset(
$_SESSION['lang'])) {
  
$lang $_SESSION['lang'];
}

if (isset(
$_GET['lang'])) {
  
$lang $_GET['lang'];
}
$_SESSION['lang'] = $lang;

$area_lang 'area_'.$lang;
$desc_lang 'desc_'.$lang;


if(
$lang =='es'){
    
$txt_addconsulta 'Agregar consulta';
    
$txt_sel_doc 'Selecione un m&eacute;dico';
    
$txt_titulo 'Asunto';
    
$txt_doctor 'M&eacute;dico';
    
$txt_mensaje 'Mensaje';
    
$btn_enviar 'Enviar';
    
$txt_error 'Su consulta no pudo ser guardada, por favor, vuelva a hacerla. Disculpe el inconveniente.';
}
else {
    
$txt_addconsulta 'Add Question';
    
$txt_sel_doc 'Select a doctor';
    
$txt_titulo 'Subjet';
    
$txt_doctor 'Doctor';
    
$txt_mensaje 'Message';
    
$btn_enviar 'Send';
    
$txt_error 'Your request could not be saved, please try it again. We apologize for the inconvenience.';
}




$id_member $_SESSION['MM_Username'];




// QUERRY DOCTOR DE CONSULTA
mysql_select_db($database_clubsha$clubsha);
$query_doc "SELECT * FROM clubsha_medicos";
$doc mysql_query($query_doc$clubsha) or die(mysql_error());
$row_doc mysql_fetch_assoc($doc);
$totalRows_doc mysql_num_rows($doc);







$addFormAction $_SERVER['PHP_SELF'];

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "addForm")) {


  
$error 0;



  
$td_add_titulo_txt reemplaza_saltos_linea_html($_POST['td_add_titulo']); 
  
$td_add_msg_txt reemplaza_saltos_linea_html($_POST['td_add_msg']);  
  
  
$date_ahora date("Y-m-d H:i:s"); 
  
  
$updateSQL sprintf("INSERT INTO clubsha_foro_status (id_med, id_user, last_preg, last_resp, last_total, last_view_user, last_view_doc, titulo)
                           VALUES (%s, %s, %s, %s, %s, %s, %s, %s) "
,
                       
GetSQLValueString($_POST['td_add_doc'], "int"),
                       
GetSQLValueString($id_member"text"),
                       
GetSQLValueString($date_ahora"date"),
                       
GetSQLValueString($date_ahora"date"),
                       
GetSQLValueString($date_ahora"date"),
                       
GetSQLValueString($date_ahora"date"),
                       
GetSQLValueString($date_ahora"date"),
                       
GetSQLValueString($td_add_titulo_txt"text"));

        
mysql_select_db($database_clubsha$clubsha);
        
$Result mysql_query($updateSQL$clubsha) or die(mysql_error());
  
   if ( 
$Result != ) {$error 1;}
  
  else {
  
          
        
// QUERY TEXTOS DE CONSULTA
        
mysql_select_db($database_clubsha$clubsha);
        
$query_td_lastid sprintf("SELECT * FROM clubsha_foro_status WHERE last_preg = %s AND last_total = %s",
                               
GetSQLValueString($date_ahora"date"),
                               
GetSQLValueString($date_ahora"date"));
                               
        
$td_lastid mysql_query($query_td_lastid$clubsha) or die(mysql_error());
        
$row_td_lastid mysql_fetch_assoc($td_lastid);
        
$totalRows_td_lastid mysql_num_rows($td_lastid);
          
          
        
mysql_select_db($database_clubsha$clubsha);
        
$updateSQL2 sprintf("INSERT INTO clubsha_foro_consultas (id_cons, preg_resp, fecha_hora, texto) VALUES (%s, %s, %s, %s) ",
                           
GetSQLValueString($row_td_lastid['id_cons'], "int"),
                           
GetSQLValueString("P""text"),
                           
GetSQLValueString($date_ahora"date"),
                           
GetSQLValueString($td_add_msg_txt"text"));

        
$Result2 mysql_query($updateSQL2$clubsha) or die(mysql_error());
  
        if ( 
$Result2 != ) {$error 1;}
  
  }
  
    if (
$error == ){
        
$updateGoTo "td_misconsultas.php";
    }
    else {    
        
$updateGoTo "td_addconsulta.php?fail=1";
    }    



  
header(sprintf("Location: %s"$updateGoTo));
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dstd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
....
....
//continua el html....


En mi PC no me sale nada, porque tengo solo los Warning ocultos y con eso funciona, en el servidor he probado con .htaccess poniendo "php_value display_errors off", con esto he logrado que no me aparezca el mensaje, pero al enviar el formulario, me ejecuta todo lo de MySQL, pero me regresa a la misma web, vamos, como si hubiera un error de php pero no me lo muestra.

Bueno, espero que me puedan ayudar, porque ni con un REDBULL he podido encontrar el fallo.

Muchas gracias de antemano como siempre...

Saludos

Carlos
__________________
=================
Chiqui nunca muere ! ! !
  #2 (permalink)  
Antiguo 26/03/2009, 13:29
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

Revisa si no es problema de la codificación del archivo.

Si estás guardando en codificación UTF-8, guárdalo sin BOM.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 26/03/2009, 13:30
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

¿No estas imprimiendo nada antes de el session_start()?
  #4 (permalink)  
Antiguo 26/03/2009, 14:23
Avatar de chiquirf  
Fecha de Ingreso: noviembre-2005
Ubicación: Madrid
Mensajes: 215
Antigüedad: 18 años, 5 meses
Puntos: 3
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

me ca$#@go en la p$#%ta codificacion de caracteres.. !!!!!

con el NotePad++ lo convertí a UTF-8 sin BOM y ya no sale el mensaje del comienzo. MUCHAS GRACIAS...!!!!

Lamentablemente ahora cuando envio el formulario me sale este error:

Warning: Cannot modify header information - headers already sent by (output started at /home/instalal/public_html/miweb/principal/clubSHA/cods/funciones.php:1) in /home/instalal/public_html/miweb/principal/clubSHA/talkdoctor/td_addconsulta.php on line 171

No estoy imprimiendo nada antes del session_start(), este tipo de formulario lo tengo muchas veces en toda la web y no me dá estos fallos...

Gracias
__________________
=================
Chiqui nunca muere ! ! !
  #5 (permalink)  
Antiguo 26/03/2009, 14:29
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

Abre el archivo funciones.php y ve si no tiene el mismo problema de codificación.

El código de error dice que la salida fue iniciada por ese archivo en la primera línea.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #6 (permalink)  
Antiguo 26/03/2009, 14:52
Avatar de chiquirf  
Fecha de Ingreso: noviembre-2005
Ubicación: Madrid
Mensajes: 215
Antigüedad: 18 años, 5 meses
Puntos: 3
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

una vez mas... me c.a.g.o en la codificacion de caracteres...

ya funciona perfecto, muchas gracias....

ahora una pregunta... cual es la diferencia entre todas las codificaciones??? y porque esto da fallos???

ANSI
UTF-8 sin BOM
UTF-8
UCS-2 Big Endian
UCS-2 Little Endian

estas son las opciones que me salen el el NotePad++

Gracias..
__________________
=================
Chiqui nunca muere ! ! !
  #7 (permalink)  
Antiguo 26/03/2009, 15:01
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

Lo que viene al caso explicar es la diferencia entre UTF-8 y UTF-8 sin BOM.

Ese BOM son 3 bytes que se escriben al inicio del archivo y que no se ven cuando se sirve como UTF-8, pero son enviados al navegador, por lo que después de enviarla no se puede usar header(), ni sesiones, ni cookies.

Por eso, cuando lo guardaste como UTF-8 sin BOM, ya no te dió problemas.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #8 (permalink)  
Antiguo 26/03/2009, 23:28
Avatar de chiquirf  
Fecha de Ingreso: noviembre-2005
Ubicación: Madrid
Mensajes: 215
Antigüedad: 18 años, 5 meses
Puntos: 3
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

pues muchas gracias... y déjame decirte que haces honor a tu nick, que grande que eres...

aunque me quedo con la duda de porqué en los otros casos si funciona, y todos los ficheros están en ANSI (según NotePad++)

Saludos

Carlos
__________________
=================
Chiqui nunca muere ! ! !
  #9 (permalink)  
Antiguo 20/05/2009, 15:07
 
Fecha de Ingreso: mayo-2009
Mensajes: 1
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

hermano como te?? yo soy de venezuela y te cuenta que he perdido dias por un estupido problema resulta que el problema reside en
LA CODIFICACION UTF-8 A ANSI. Php solo utiliza ansi!!
ANSI
  #10 (permalink)  
Antiguo 28/06/2009, 12:14
 
Fecha de Ingreso: junio-2009
Mensajes: 5
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

Muy buena la información de la codificación, resolví mis problemas...!!


Gracias.:!
  #11 (permalink)  
Antiguo 28/06/2009, 12:24
 
Fecha de Ingreso: marzo-2008
Mensajes: 166
Antigüedad: 16 años
Puntos: 5
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

@chiquirf ya te explicó David. El problema es que para usar headers, cookies y sesiones necesitas no haber enviado algo al navegador. Algo que con la condificación UTF-8 con BOM es imposible porque escribe 3 bytes invisibles al inicio de los archivos y las otras codificaciones no lo hacen.

Saludos.
  #12 (permalink)  
Antiguo 28/06/2009, 14:54
 
Fecha de Ingreso: agosto-2006
Ubicación: Monterrey, N.L.
Mensajes: 67
Antigüedad: 17 años, 8 meses
Puntos: 2
Respuesta: Warning: session_start() [function.session-start]: Cannot send session cac

Cita:
Iniciado por David Ver Mensaje
Ese BOM son 3 bytes que se escriben al inicio del archivo y que no se ven cuando se sirve como UTF-8, pero son enviados al navegador, por lo que después de enviarla no se puede usar header(), ni sesiones, ni cookies.
Gracias, tenia ese problema.

Saludos.
__________________
El mundo es tuyo.
Para mi fortuna el universo es demasiado grande.

Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:26.