Foros del Web » Programando para Internet » PHP »

Redireccion login

Estas en el tema de Redireccion login en el foro de PHP en Foros del Web. Hola a todoss! Tengo un codigo php de un login y me gustaria saber como puedo hacer para que vuelva a la pagina anterior donde ...
  #1 (permalink)  
Antiguo 19/08/2010, 10:14
Avatar de ale_dla  
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 189
Antigüedad: 15 años
Puntos: 3
Redireccion login

Hola a todoss!
Tengo un codigo php de un login y me gustaria saber como puedo hacer para que vuelva a la pagina anterior donde estaba antes capaz qe con javascript se puede.
Este es mi script:
Código PHP:
   <?php
//signin.php
include 'header.php';

echo 
'<h3>Sign in</h3><br />';

//first, check if the user is already signed in. If that is the case, there is no need to display this page
if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true)
{
    echo 
'You are already signed in, you can <a href="signout.php">sign out</a> if you want.';
}
else
{
    if(
$_SERVER['REQUEST_METHOD'] != 'POST')
    {
        
/*the form hasn't been posted yet, display it
          note that the action="" will cause the form to post to the same page it is on */
        
echo '<form method="post" action="">
            Username: <input type="text" name="usuario" /><br />
            Password: <input type="password" name="password"><br />
            <input type="submit" value="Sign in" />
         </form>'
;
    }
    else
    {
        
/* so, the form has been posted, we'll process the data in three steps:
            1.    Check the data
            2.    Let the user refill the wrong fields (if necessary)
            3.    Varify if the data is correct and return the correct response
        */
        
$errors = array(); /* declare the array for later use */
        
        
if(!isset($_POST['usuario']))
        {
            
$errors[] = 'The username field must not be empty.';
        }
        
        if(!isset(
$_POST['password']))
        {
            
$errors[] = 'The password field must not be empty.';
        }
        
        if(!empty(
$errors)) /*check for an empty array, if there are errors, they're in this array (note the ! operator)*/
        
{
            echo 
'Uh-oh.. a couple of fields are not filled in correctly..<br /><br />';
            echo 
'<ul>';
            foreach(
$errors as $key => $value/* walk through the array so all the errors get displayed */
            
{
                echo 
'<li>' $value '</li>'/* this generates a nice error list */
            
}
            echo 
'</ul>';
        }
        else
        {
            
//the form has been posted without errors, so save it
            //notice the use of mysql_real_escape_string, keep everything safe!
            //also notice the sha1 function which hashes the password
            
$sql "SELECT 
                        usuario_id,
                        usuario,
                        usuario_nivel
                    FROM
                        usuarios
                    WHERE
                        usuario = '" 
mysql_real_escape_string($_POST['usuario']) . "'
                    AND
                        password = '" 
sha1($_POST['password']) . "'";
                        
            
$result mysql_query($sql);
            if(!
$result)
            {
                
//something went wrong, display the error
                
echo 'Something went wrong while signing in. Please try again later.';
                
//echo mysql_error(); //debugging purposes, uncomment when needed
            
}
            else
            {
                
//the query was successfully executed, there are 2 possibilities
                //1. the query returned data, the user can be signed in
                //2. the query returned an empty result set, the credentials were wrong
                
if(mysql_num_rows($result) == 0)
                {
                    echo 
'You have supplied a wrong user/password combination. Please try again.';
                }
                else
                {
                    
//set the $_SESSION['signed_in'] variable to TRUE
                    
$_SESSION['signed_in'] = true;
                    
                    
//we also put the user_id and user_name values in the $_SESSION, so we can use it at various pages
                    
while($row mysql_fetch_assoc($result))
                    {
                        
$_SESSION['usuario_id']     = $row['usuario_id'];
                        
$_SESSION['usuario']     = $row['usuario'];
                        
$_SESSION['usuario_nivel'] = $row['usuario_nivel'];
                    }
                    
// aca quiero redireccionar 
                    
echo 'Welcome, ' $_SESSION['usuario'] . '. <br /><a href="index.php">Proceed to the forum overview</a>.';
                }
            }
        }
    }
}

include 
'footer.php';
?>
Quien pueda ayudarme se los agradezco,
Muchas gracias. !
  #2 (permalink)  
Antiguo 19/08/2010, 10:19
 
Fecha de Ingreso: agosto-2010
Ubicación: Madrid
Mensajes: 53
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Redireccion login

Pues cuando tengas que redireccionarlo hacia la pagina de antes pones esto:

echo "<script>parent.location.href='pagina.php'</script>";

Si quieres a pagina.php tambien le puedes añadir variables : ='pagina.php?pag=".$pag."'
  #3 (permalink)  
Antiguo 19/08/2010, 10:24
 
Fecha de Ingreso: agosto-2010
Ubicación: santiago, CHILE
Mensajes: 564
Antigüedad: 13 años, 8 meses
Puntos: 9
Respuesta: Redireccion login

//...asi nomas ...<script>location.replace("pagina.php");</script>

//...ese es mi aporte....sin parent a lo choro nomas...
  #4 (permalink)  
Antiguo 19/08/2010, 10:31
Avatar de ale_dla  
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 189
Antigüedad: 15 años
Puntos: 3
Respuesta: Redireccion login

Gracias amigos por responder !
Pero como yo quiero que vuelva a la pagina anterior no puedo poner:
echo "<script>history.go(-1);</script>";

Gracias !
  #5 (permalink)  
Antiguo 19/08/2010, 10:40
 
Fecha de Ingreso: agosto-2010
Ubicación: santiago, CHILE
Mensajes: 564
Antigüedad: 13 años, 8 meses
Puntos: 9
Respuesta: Redireccion login

Iniciado por Atomycko Ver Mensaje
history.back() solo es para eso, para regresar a la pagina anterior o mas atras dependiendo el numero que coloques en "back()" (ejem: "javascript:history.back(5)" = 5 paginas atras).

//..esto es de un post anterior...
  #6 (permalink)  
Antiguo 19/08/2010, 10:53
 
Fecha de Ingreso: agosto-2010
Mensajes: 79
Antigüedad: 13 años, 8 meses
Puntos: 2
Respuesta: Redireccion login

pasa que eso es js.... osea... puede depender del browser... si mandas el location en el header (antes de mandar datos obviamente para que los headers no se manden primero).. es transparente para el cliente

Etiquetas: login, redireccionar
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 17:26.