Ver Mensaje Individual
  #8 (permalink)  
Antiguo 21/06/2008, 05:34
Janire
 
Fecha de Ingreso: septiembre-2007
Mensajes: 100
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: Volver a la última página visitada

Muchas gracias almarin!!

Ya me funciona lo de redirigir la página después de logearse el usuario pero el problema es que siempre me va al index.html y no a la página que estaba visitando antes del login.

En vez de con header(location) lo he tenido que hacer con <head><meta> ya que si no me daba un error.

No sé como solucionarlo, ¿alguna idea?

Os pongo el código:

login.php
Código PHP:
<?php
    session_start
();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Identificación de usuarios</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="verify-v1" content="7uiD5QdUtd0j14COc+V8QRQHTsLmS+qE5PWC/+OaSYQ=" />
    <meta name="revisit" content="1 semana">
    <link href="estilo.css" type="text/css" rel="stylesheet" />
    <script language="javascript" src="popup.js"></script>
    <meta content="MSHTML 6.00.2800.1400" name="GENERATOR" />
    <style type="text/css">
        body 
        {
            margin-left: 10px;
            margin-top: 10px;
        }
    </style>
</head>

<?php
    $primeravez 
FALSE;
    if (empty(
$_POST["botEnviar"]))
    {
        
$primeravez TRUE;
        
$_POST["email"] = "";
        
$_POST["contrasena"] = "";
    }
?>

<body bgcolor="#F5F5F5" topmargin="10">
    <table width="836" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td colspan="2" width="836">
                <iframe name="navigation" src="cabecera.html" frameborder="0" width="836" scrolling="no" height="118"></iframe>
            </td>
        </tr>
        <tr>
            <td colspan="2" width="836" height="22"></td>
        </tr>
        <tr>
            <td colspan="2" width="836" height="30" bgcolor="#FFFFFF">Para poder acceder a su cuenta de usuario, debe identificarse. Si no está registrado, hagalo pulsando <a href="registro.php">aquí</a>.</td>
        </tr>
        <tr>
            <td colspan="2" width="836" height="8" bgcolor="#FFFFFF"></td>
        </tr>
    <form name="login" method="post" action="login.php">
        <tr>
            <td width="100" bgcolor="#FFFFFF">Email *:</td>
              <td width="736" bgcolor="#FFFFFF"><input name="email" type="text" id="email" value="<?php echo $_POST['email']; ?>" size="40" style="background-color:#F5F5F5" /></td>
        </tr>
        <?php
            
if (!$primeravez)
            {
                if (empty(
$_POST["email"]))
                    echo 
"<tr><td colspan=\"2\" width=\"836\" height=\"25\" bgcolor=\"#FFFFFF\" style=\"color:#FF0000; font-size:14px\">¡Tiene que introducir su email!</td></tr>";
                elseif (!
eregi("^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9_\-\.]+$"$_POST["email"]))
                    echo 
"<tr><td colspan=\"2\" width=\"836\" height=\"25\" bgcolor=\"#FFFFFF\" style=\"color:#FF0000; font-size:14px\">¡Email no válido!</td></tr>";
                else
                    
$email htmlspecialchars($_POST["email"]);
            }
        
?>
        <tr>
            <td colspan="2" height="8" bgcolor="#FFFFFF"></td>
        </tr>
        <tr>
            <td width="100" bgcolor="#FFFFFF">Contraseña *:</td>
              <td width="736" bgcolor="#FFFFFF"><input name="contrasena" type="password" id="contrasena" value="<?php echo $_POST['contrasena']; ?>" size="40" style="background-color:#F5F5F5" /></td>
        </tr>
        <?php
            
if (empty($_POST["contrasena"]) && (!$primeravez))
                echo 
"<tr><td colspan=\"2\" width=\"836\" height=\"25\" bgcolor=\"#FFFFFF\" style=\"color:#FF0000; font-size:14px\">¡Tiene que introducir su contraseña!</td></tr>";
            else
                
$contrasena htmlspecialchars($_POST["contrasena"]);
        
?>
        <tr>
            <td colspan="2" width="836" height="8" bgcolor="#FFFFFF"></td>
        </tr>
        <tr>
              <td colspan="2" width="836" bgcolor="#FFFFFF" align="center"><input name="botEnviar" type="submit" id="botEnviar" value="Enviar" style="width:100px; cursor:pointer" /></td>
        </tr>
    </form>
    <?php
        
if ((!$primeravez) && isset($email) && isset($contrasena))
        {
            require_once(
"conexion.inc.php");
            
$conexion mysql_connect($servidor$usuario$passwd);
            
$db mysql_select_db($basedatos$conexion);
            if (!
$conexion)
            {
                echo 
"Error al establecer la conexión con la base de datos: " mysql_error();
                exit();
            }
            if (!
$db)
            {
                echo 
"Error seleccionando la base de datos: " mysql_error();
                exit();
            }
            
$resultado mysql_query("SELECT id_cliente FROM clientes WHERE email = '$email' AND contrasena = '$contrasena'"$conexion);
            if (
mysql_num_rows($resultado) > 0)
            {
                
$fila mysql_fetch_array($resultado);
                
$_SESSION["usuario"] = $fila["id_cliente"];
                
$_SESSION["logged"] = TRUE;
                echo 
"<tr><td colspan=\"2\" width=\"836\" height=\"15\" bgcolor=\"#FFFFFF\"></td></tr><tr><td colspan=\"2\" width=\"836\" heigth=\"25\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"color:#33CC00; font-size:14px\">Identificación realizada con éxito.</td></tr>";
                
$destino = isset($_GET['referer']) ? $_GET['referer'] : 'index.html';
                echo 
"<head><meta http-equiv=\"refresh\" content=\"3; url=$destino\"></head>";
            }
            else
            {
                echo 
"<tr><td colspan=\"2\" width=\"836\" height=\"15\" bgcolor=\"#FFFFFF\"></td></tr><tr><td colspan=\"2\" width=\"836\" heigth=\"25\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"color:#FF0000; font-size:14px\">¡Usuario o contraseña incorrectos!</td></tr>";
            }
            
mysql_free_result($resultado);
            
mysql_close($conexion);
        }
    
?>
        <tr>
            <td height="20" bgcolor="#F5F5F5" colspan="6"></td>
        </tr>
    </table>
</body>
</html>
Sigue más abajo.