![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
20/01/2011, 08:36
|
| | Fecha de Ingreso: enero-2011
Mensajes: 56
Antigüedad: 14 años, 1 mes Puntos: 1 | |
Respuesta: Problema sesiones Bien pues estos son los codigos:
Login.php:
<html>
<body bgcolor="#BDBDBD" link="black" alink="black" vlink="black">
<center><h1><font color="white">Desvario</font></h1></center>
<hr>
<br>
<br>
<table align=center valign=middle border=3 bordercolor="white">
<tr>
<td>
<form action="validar_usuario.php" method="post">
Usuario:<input type="text" name="usuario" size="20" maxlength="20" />
<br />
Password:<input type="password" name="password" size="10" maxlength="10" />
<br />
<center><a href="http://www.redesp.uphero.com/index.html">Volver al Inicio</a>
<br>
<input type="submit" value="Ingresar" /></center>
</form>
</td>
</tr>
</table>
</body>
</html>
VALIDAR_USUARIO.PHP:
<?php session_start();
//datos para establecer la conexion con la base de mysql.
mysql_connect('host','usuario','password')or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('bd')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function quitar($mensaje)
{
$nopermitidos = array("'",'\\','<','>',"\"");
$mensaje = str_replace($nopermitidos, "", $mensaje);
return $mensaje;
}
if(trim($HTTP_POST_VARS["usuario"]) != "" && trim($HTTP_POST_VARS["password"]) != "")
{
$usuario = strtolower(htmlentities($HTTP_POST_VARS["usuario"], ENT_QUOTES));
$password = $HTTP_POST_VARS["password"];
$result = mysql_query('SELECT password, usuario FROM usuarios WHERE usuario=\''.$usuario.'\'');
if($row = mysql_fetch_array($result)){
if($row["password"] == $password){
$_SESSION["k_username"] = $row['usuario'];
header("Location: index.php");
echo 'Has sido logueado correctamente '.$_SESSION['k_username'].' <p>';
echo '<a href="index.php">Index</a></p>';
<SCRIPT LANGUAGE="javascript">
location.href = "index.php";
</SCRIPT>*/
}else{
echo 'Password incorrecto';
}
}else{
echo 'Usuario no existente en la base de datos';
}
mysql_free_result($result);
}else{
echo 'Debe especificar un usuario y password';
}
mysql_close();
?>
INDEX.PHP:
<html>
<head>
<title>Problema</title>
<link rel="StyleSheet" href="estilos.css" type="text/css">
</head>
<body>
include("config.php");
<div id="contenedor">
<div id="cabecera">
<table>
<tr>
<td><a href="http://www.redesp.uphero.com/mensajes/index.php">Mensajes</a>
</td>
</tr>
</table>
</div>
<div id="columna1">
<?php session_start();
if (isset($_SESSION['k_username'])) {
echo '<b>'.$_SESSION['k_username'].'</b>.';
echo '<p><a href="logout.php">Logout</a></p>';
echo '<b>'.$SESSION['email'].'</b>';
}else{
header ("Location: http://www.redesp.uphero.com/index.html");
}
?>
</div>
<div id="columna2">
<h2>Título de la columna</h2>
<p>Contenido de la columna2. </p>
</div>
<div id="pie">
Pié de página.
</div>
</div>
</body>
</html>
Y aqui la pagina donde se me pierde la sesion (un sistema de mensajeria interna):
<?php
session_start();
mysql_connect("host","usuario", "password") or die ("Hubo un error al procesar los solicitado");
mysql_select_db("bd");
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="alfonso">
<title>Mensajes</title>
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
if(isset($_GET["delete"])) {
$id = $_GET["delete"];
if(mysql_query("DELETE FROM `mensajes-privados` WHERE id = '$id'")) {
echo "<div id='bien'><img src='Imagenes/bien.png' /> El mensaje ha sido elimiando con éxito</div>";
} else {
echo "<div id='error'><img src='Imagenes/error.png' /> El mensaje no puedo ser elimiando. Vuelve a intentarlo en unos minutos</div>";
}
}
?>
<div class='mensajes'>
<?php
if(!isset($_SESSION["conectado"])){
echo "<div id='error'><img src='Imagenes/error.png' /> Debes ingresar para poder enviar mensajes</div>";showFrom();
}
else {
showFrom();
}
?>
<?php function showFrom() { ?>
<div class='carpeta'><strong>Carpeta: inbox </strong></div>
<div class='espacio'>-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div class='menu'><strong><a href="index.php"><img src="Imagenes/recibido.gif" width="18" height="13" border="0"> Mensajes recibidos </a></strong><br>
<br>
<strong><a href="redactar.php"><img src="Imagenes/escribir.gif" width="17" height="17" border="0"> Escribir mensaje</a></strong></div>
<div class='leer'>
<?php
$user = $_SESSION['usuario'];
$q = "SELECT * FROM `mensajes-privados` WHERE para = '$user' ORDER BY id DESC";
if(!($result_set = mysql_query($q))) die(mysql_error());
$number = mysql_num_rows($result_set);
if ($number) {
while ($row = mysql_fetch_array($result_set))
{
$mid[] = $row['id'];
$mde[] = $row['de'];
$masunto[] = $row['asunto'];
$mleido[] = $row['leido'];
}
$max_show = 5;
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$from2 = $page * $max_show;
if ($from2 > $number)
{
$diff = $number % $max_show;
$from2 = $number;
$from1 = $from2 - $diff;
}
else
$from1 = $from2 - $max_show;
echo "<table border='1' width=550px style='FONT-SIZE: 12px;'><tr height=50>";
echo "<td> </td>
<td> <b><u>Remitente</u></b></td>
<td> <b><u>Asunto</u></b></td>
<td> <b><u>Leido</u></b></td>
<td> <b><u>Acción</u></b></td></tr>";
for ($i=$from1; $i < $from2; $i++) {
echo "<tr>";
echo "<td> <a href=\"leer.php?id={$mid[$i]}\"><img src='Imagenes/mensaje-abierto.gif' border='0'> Leer</a></td>
<td> {$mde[$i]}</td>
<td> {$masunto[$i]}</td>
<td> {$mleido[$i]}</td>
<td> <a href=\"index.php?delete={$mid[$i]}\"><img src='Imagenes/borrar.png'></a></b></td>";
}
echo "</tr></table>";
echo "<br><br><table width='550px' border='0'><tr>";
echo "<td align='right' width='50%'> ";
if ($from1 > 0)
{
$previous = $page - 1;
echo "<a href='index.php?page=$previous'><< Página anterior</a>";
} echo "</td>";
echo "<td align=left width=50%> ";
if ($from2 < $number)
{
$next = $page + 1;
echo "<a href='index.php?page=$next'>Página siguiente >></a>";
} echo "</td></tr></table>";
}
else
echo "<strong>No tienes ningún mensaje.</strong>";
}
?>
</div>
</div>
</body>
</html>
Y este es el codigo, gracias :D |