Foros del Web » Programando para Internet » PHP »

error de session

Estas en el tema de error de session en el foro de PHP en Foros del Web. tengo un problema con el start session() me crea el siguiente error warning: cannot modify headers already sent by (output started at C:\xampp\php\PEAR\adodb\adodb.inc.php:483\)in C:\xampp\htdocs\prograwe\practica\valid.php on ...
  #1 (permalink)  
Antiguo 09/11/2010, 11:03
 
Fecha de Ingreso: noviembre-2010
Mensajes: 105
Antigüedad: 13 años, 5 meses
Puntos: 0
Exclamación error de session

tengo un problema con el start session() me crea el siguiente error
warning: cannot modify headers already sent by (output started at C:\xampp\php\PEAR\adodb\adodb.inc.php:483\)in C:\xampp\htdocs\prograwe\practica\valid.php on line 16
userpass.php
<html>
<head>
<title>Autentificación PHP</title>
</head>
<body>
<h1>Autentificación De Usuario</h1>
<form action="valid.php" method="POST">
<table align="center" width="225" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center"
<?php if ($_GET["errorusuario"]=="si"){?>
bgcolor=red><span style="color:ffffff"><b>Datos incorrectos</b></span>
<?php }else{?>
bgcolor=#cccccc>Introduce tu clave de acceso
<?php }?></td>
</tr>
<tr>
<td align="right">USER:</td>
<td><input type="Text" name="usuario" size="8" maxlength="50"></td>
</tr>
<tr>
<td align="right">PASSWD:</td>
<td><input type="password" name="contrasena" size="8" maxlength="50"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="Submit" value="ENTRAR"></td>
</tr>
</table>
</form>
</body>
</html>
---------------------------------
<?php
include_once "bd/base_anotador.php";//inicializa la base de datos
include_once 'bd/table.php';//funciones para una tabla
$usuario=$_POST['usuario'];
$contrasena=$_POST['contrasena'];
$base->debug_on(true);
$tbl=new table('cliente',$base);
global $tbl;
$x = $tbl->select('*',"usuario='$usuario' and contrasena='$contrasena'","' '");
if ($x->numrows()!=0){
session_start();
session_register("autentificado");
$autentificado = "SI";
header("Location:servicios.php");
}else {
header("Location:userpass.php?errorusuario=si");
}
?>
------------------------------------------
<?php

include_once 'base.php';

class table
{
public $table_name;

private $base=null;
private $campos = array();
public $rs=null;

//************************************************** ******
public function __construct($table='', $base=null)
{
$this->table_name = $table;
$this->base = &$base;
}
//************************************************** ******
public function __set($name, $value)
{
$this->campos[$name] = $value;
}
//************************************************** *******
public function __get($name)
{
$ret = null;

if (array_key_exists($name, $this->campos))
$ret = $this->campos[$name];

if ($name == 'RecordCount')
{if ($this->rs)
$ret = $this->rs->RecordCount();
else
$ret = -1;
}

if ($name == 'Registro')
$ret = $this->campos;
return $ret;
}
//************************************************** ******
private function GetFields() // doesn´t work with empty table
{
$sql = "select * from {$this->table_name}";
$rs = $this->base->dosql_limit($sql, 1);
return $rs->fields;
}
//************************************************** ******
public function AutoLoadFields()
{
$this->campos = $this->GetFields();
}
//************************************************** ******
function Save()
{
$this->base->Insert($this->table_name, $this->campos);
}

//************************************************** ******
function AssignFields($valores) // Asigna un arreglo de campos
{
$campos = $this->GetFields();
foreach($valores as $key => $val)
{
if (array_key_exists($key, $campos))
$registro[$key]=$val;
}
// var_dump($registro);
$this->campos = $registro;
}
//************************************************** ******
function SaveArray($valores) // recibe arregelo de campos y los almacena en la tabla
{
$this->AssignFields($valores);
$this->Save();
}
//************************************************** ******
function Update($where=false)
{
$this->base->Update($this->table_name, $this->campos,'UPDATE', $where);
}
//************************************************** ******
function InsUpd($key='', $autoquote=false)
{
if ($key == '') $key = $campos[0]; // primer campo id por defecto
$this->base->InsUpd($this->table_name, $this->campos, $key, $autoquote);
}
//************************************************** ******
function Select($campos, $where='', $orderfield='')
{
if ($where != '') $where = " where $where";
if ($orderfield != '') $orderfield = " order by $orderfield";
$sql = "select $campos from {$this->table_name} $where $orderfield";
$this->rs = $this->base->dosql($sql);
if ($this->rs)
$this->campos = $this->rs->fields;
return($this->rs);
}
//************************************************** ******
function Find($valor, $campo_where='') // por defecto busca por la llave primaria
{
if ($campo_where == '') $campo_where = $this->base->GetPK($this->table_name);
return $this->Select('*', "$campo_where = '$valor' ");
}
//************************************************** ******
function Delete($valor, $campo_where='') // por defecto borra por la llave primaria
{
$res = false;
if ($this->Find($valor, $campo_where))
{$res = true;
if ($campo_where == '') $campo_where = $this->base->GetPK($this->table_name);
while(!$this->rs->EOF)
{
$val_campo = $this->rs->fields[$campo_where];
$sql = "delete from {$this->table_name} where $campo_where = $val_campo";
$this->base->dosql($sql);
$this->rs->MoveNext();
}
}
return($res);
}
//************************************************** ******
function GetCombo($name, $id='', $valor='', $defa='')
{$cam = $this->campos;
reset($cam); // echo '-->'.key($cam);
if ($id == '')
{$id = key($cam); next($cam);}
if ($valor == '') $valor = key($cam);
// var_dump($id); var_dump($valor);
while(!$this->rs->EOF)
{ $key = $this->rs->fields[$id];
$val = $this->rs->fields[$valor];
$opt .= "<option value = \"$key\">$val</option>\n";
$this->rs->MoveNext();
}
$res = "<select name=\"$name\">\n$opt\n</select>";
return($res);
}
//************************************************** ******
function ShowRecord()
{
echo "<pre>";
var_dump($this->campos);
echo "</pre>";
}
//************************************************** ******
function GetRows($field='')
{$res = '';
if (($this->rs == null) || (!is_array($this->campos))) return('');
if ($field == '') $field = key(($this->campos));
while(!$this->rs->EOF)
{ $res .= $this->rs->fields[$field]."<br/>\n";
$this->rs->MoveNext();
}
return($res);
}
//************************************************** ******
function Error()
{
return($this->base->ErrorNo() != 0);
}
//************************************************** ******

}
?>
  #2 (permalink)  
Antiguo 09/11/2010, 11:06
Avatar de ElJavista
Colaborador
 
Fecha de Ingreso: marzo-2007
Ubicación: Lima Perú
Mensajes: 2.231
Antigüedad: 17 años, 1 mes
Puntos: 67
Respuesta: error de session

Ese es el clásico String antes session_start(); el cual debes poner al principio de código, antes de cualquier cosa. Si eso no te resulta guarda el archivo como UTF-8 sin bom. Suerte!
  #3 (permalink)  
Antiguo 09/11/2010, 11:13
 
Fecha de Ingreso: noviembre-2010
Ubicación: laudio
Mensajes: 61
Antigüedad: 13 años, 5 meses
Puntos: 1
Respuesta: error de session

Tal como te dice el amigo de arriba, session_start() debes ponerlo arriba del todo. Mejor dicho, y dicho de otra forma, antes de session_start() no debes de escribir nada en la pagina html (ya sea cualquier etiqueta html o informacion con echo).
  #4 (permalink)  
Antiguo 09/11/2010, 12:11
 
Fecha de Ingreso: septiembre-2009
Mensajes: 56
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: error de session

Lo que pasa es que el session_start() funciona solo si no se ha enviado nada al cliente.... ningun echo, ni ninguna etiqueta html.

Como consejo... pega tu codigo entre etiquetas php para facilitar la lectura.

ojala te sirva
  #5 (permalink)  
Antiguo 09/11/2010, 14:52
 
Fecha de Ingreso: noviembre-2010
Mensajes: 105
Antigüedad: 13 años, 5 meses
Puntos: 0
Exclamación Respuesta: error de session

sii q pena no haberlo posteado bn se me paso, pero ya intente el consejo q todos me dieron de poner session_start() antes q cualquier cosa y quedo asi: pero ahhora me sale este error¡¡¡
Código PHP:
<?php session_start();
 include_once 
"bd/base_anotador.php";
 include_once 
'bd/table.php';
$usuario=$_POST['usuario'];
$contrasena=$_POST['contrasena'];
$base->debug_on(true); 
$tbl=new table('cliente',$base);
global 
$tbl;
$x $tbl->select('*',"usuario='$usuario' and contrasena='$contrasena'","' '");
if (
$x->numrows()!=0){                
       
session_register("autentificado"); 
       
$autentificado "SI"
       
header("Location:servicios.php");
}else { 
   
header("Location:userpass.php?errorusuario=si"); 

?>
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\php\PEAR\adodb\adodb.inc.php:483) in C:\xampp\htdocs\prograweb\practica\valid.php on line 15
  #6 (permalink)  
Antiguo 09/11/2010, 14:57
Avatar de masterojitos  
Fecha de Ingreso: julio-2008
Ubicación: Lima Callao Chucuito
Mensajes: 1.931
Antigüedad: 15 años, 9 meses
Puntos: 105
Respuesta: error de session

Eso aparece cuando usas el header() y antes has imprimido html....

Segun creo que es esto $base->debug_on(true); lo cual supongo que imprime un mensaje en la web... y eso no deberia de estar... comentalo y prueba.

Suerte
__________________
Atte. MasterOjitos :ojotes:
Todo sobre Programación Web
Las ultimas tendencias en Efectos y Recursos Web: MasterOjitos Blog
  #7 (permalink)  
Antiguo 09/11/2010, 15:39
 
Fecha de Ingreso: noviembre-2010
Mensajes: 105
Antigüedad: 13 años, 5 meses
Puntos: 0
De acuerdo Respuesta: error de session

Masterojitos sos de lo mejor¡¡ t agradezco ya me estaba volviendo loco y me iba a poner a hacer un monton de cosas innecesarias gracias¡¡

Etiquetas: session
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 22:56.