Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/05/2012, 01:28
Avatar de ArturoGallegos
ArturoGallegos
Moderador
 
Fecha de Ingreso: febrero-2008
Ubicación: Morelia, México
Mensajes: 6.774
Antigüedad: 16 años, 2 meses
Puntos: 1146
Respuesta: probema redireccionar pag solo la primera vez

creo que no me terminas de entender, bien te daré un ejemplo funcional, y vale aclarar que en $value = 'cualquier cosa'; no importa que pongas lo importante es $_POST['password'] donde password es el nombre del input donde han introducido su contraseña en la pagina de login, en el ejemplo anterior no hacia comprobación de la clave en este ejemplo lo modifique un poco para revisar que la clave sea correcta.

bien creamos un index.php , este revisa que exista la coockie o que haya insertado la contraseña correctamente
Código PHP:
Ver original
  1. <?
  2. $pass = $_POST['password'];
  3. if(isset($_COOKIE['TestCookie']) || ($pass=='12345')) {
  4.     $value = 'cualquier cosa';
  5.     setcookie("TestCookie", $value, time() + 300);
  6. ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  9.  
  10. <head>
  11.     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  12.     <meta name="author" content="Ag666" />
  13.  
  14.     <title>Home</title>
  15. </head>
  16.  
  17. <body>
  18. <h1>Contenido de nuestro sitio</h1>
  19. <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a</p><br />
  20. <a href="AboutUs.php">About Us</a>
  21.  
  22. </body>
  23. </html>
  24. <?
  25. }
  26. else {
  27.     header ("Location: Login.php");
  28. }
  29. ?>

Creamos nuestra pagina Login.php para que inserten la contraseña
Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3.  
  4. <head>
  5.     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  6.     <meta name="author" content="Ag666" />
  7.  
  8.     <title>Iniciar Sesión</title>
  9. </head>
  10.  
  11. <body>
  12.  
  13. <form action="index.php" method="post">
  14.     <input type="password" name="password" />
  15.     <input type="submit" value="Aceptar" />
  16. </form>
  17.  
  18. </body>
  19. </html>

Y una pagina interna AboutUs.php por lo que pides que si guardan en bookmark igual le pida la clave, la pagina interna solo revisara si existe la coockie o lo manda a insertar la clave.
Esto implica que el usuario siempre sera llevado al home después de insertar la clave.

Código PHP:
Ver original
  1. <?
  2. if(isset($_COOKIE['TestCookie'])) {
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6.  
  7. <head>
  8.     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  9.     <meta name="author" content="Ag666" />
  10.  
  11.     <title>About Us</title>
  12. </head>
  13.  
  14. <body>
  15.  
  16. <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  17.  
  18. </body>
  19. </html>
  20. <?
  21. }
  22. else {
  23.     header ("Location: Login.php");
  24. }
  25. ?>

te dejo un link, para que lo veas en acción
http://bit.ly/Jbzryf

Por cierto para mi ejemplo a contraseña es 12345 tal como puedes ver en esta linea if(isset($_COOKIE['TestCookie']) || ($pass=='12345'))
considerando que la clave es una sola para todos los usuarios.

Última edición por ArturoGallegos; 20/05/2012 a las 01:50