Ayuda con $_SESSION
Publicado por Mike (17 intervenciones) el 05/03/2010 15:34:36
Que tal listeros, espero y me puedan ayudar..estoy tranta de utilizar las sesiones en una pagina, pero no he logrado que me funcione, aqui esta el codigo que estoy utilizando:
======================================================
index.php
<html>
<head>
<title> Login </title>
<style type="text/css">
<!--
.Estilo1 {
font-size: 24px;
color: #0000FF;
}
-->
</style>
</head>
<body>
<br> <br> <br> <br> <br> <br> <br> <br> <br>
<form id="form1" name="form1" method="POST" action="check.php">
<table width="23%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30%"> </td>
<td width="70%"> </td>
</tr>
<tr>
<td height="33"><strong>user</strong></td>
<td>
<label>
<input name="userp" type="text" id="user" />
</label>
</td>
</tr>
<tr>
<td><strong>Password</strong></td>
<td>
<label>
<input name="pass" type="password" id="pass" />
</label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
</td>
<td> <br> <input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
</body>
</html>
======================================================
check.php
<?php
session_start();
include'connect.php';
if($_POST["userp"]=="" or $_POST["pass"]=="")
{
@header("Location: index.php?error=box_en_blanco");
}
else
{
user='".$_POST["userp"]."'",$db);
$query=mysql_query("select user from usuarios where clave='".$_POST["pass"]."' and user='".$_POST["userp"]."'",$db);
$persona = $_POST["userp"];
if (mysql_num_rows($query) == 1)
{
$_SESSION['usuario'] = $persona;
//$_SESSION['usuario'] = 'Lalo';
@header("Location: principal.php");
}
else
{
@header("Location: index.php?error=usuario_erronio");
}
}
?>
======================================================
En la pagina conexion solo guardo las variables para conectarme a la db.
======================================================
principal.php
<?
session_start();
?>
<html>
<head>
<title> </title>
</head>
<body>
<?
echo $_SESSION['usuario']; ?>
Bienvenido <? echo $_SESSION['usuario']; ?>
</body>
</html>
Cuando me valido o escribor el usuario y password, me funciona bien, el unico gran problema, es que en la pagina prinicipal.php, no me despliega el usuario o el valor de la variable SESSION que se guardo en la pagina check.php....
tiene algo que ver que utilice ===@header("Location: principal.php"); === para redireccionar la pagina a otro lado?
espero y alguien me pueda ayudar...Saludos
======================================================
index.php
<html>
<head>
<title> Login </title>
<style type="text/css">
<!--
.Estilo1 {
font-size: 24px;
color: #0000FF;
}
-->
</style>
</head>
<body>
<br> <br> <br> <br> <br> <br> <br> <br> <br>
<form id="form1" name="form1" method="POST" action="check.php">
<table width="23%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30%"> </td>
<td width="70%"> </td>
</tr>
<tr>
<td height="33"><strong>user</strong></td>
<td>
<label>
<input name="userp" type="text" id="user" />
</label>
</td>
</tr>
<tr>
<td><strong>Password</strong></td>
<td>
<label>
<input name="pass" type="password" id="pass" />
</label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
</td>
<td> <br> <input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
</body>
</html>
======================================================
check.php
<?php
session_start();
include'connect.php';
if($_POST["userp"]=="" or $_POST["pass"]=="")
{
@header("Location: index.php?error=box_en_blanco");
}
else
{
user='".$_POST["userp"]."'",$db);
$query=mysql_query("select user from usuarios where clave='".$_POST["pass"]."' and user='".$_POST["userp"]."'",$db);
$persona = $_POST["userp"];
if (mysql_num_rows($query) == 1)
{
$_SESSION['usuario'] = $persona;
//$_SESSION['usuario'] = 'Lalo';
@header("Location: principal.php");
}
else
{
@header("Location: index.php?error=usuario_erronio");
}
}
?>
======================================================
En la pagina conexion solo guardo las variables para conectarme a la db.
======================================================
principal.php
<?
session_start();
?>
<html>
<head>
<title> </title>
</head>
<body>
<?
echo $_SESSION['usuario']; ?>
Bienvenido <? echo $_SESSION['usuario']; ?>
</body>
</html>
Cuando me valido o escribor el usuario y password, me funciona bien, el unico gran problema, es que en la pagina prinicipal.php, no me despliega el usuario o el valor de la variable SESSION que se guardo en la pagina check.php....
tiene algo que ver que utilice ===@header("Location: principal.php"); === para redireccionar la pagina a otro lado?
espero y alguien me pueda ayudar...Saludos
Valora esta pregunta


0