Foros del Web » Programando para Internet » PHP »

Problema con inicio de sesion

Estas en el tema de Problema con inicio de sesion en el foro de PHP en Foros del Web. buenos dias necesito ayuda con el inicio de sesion. tengo el siguiente codigo en la pagina del formulario. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original <!DOCTYPE ...
  #1 (permalink)  
Antiguo 24/01/2011, 10:33
Avatar de skiper0125  
Fecha de Ingreso: octubre-2010
Ubicación: $this->Mexico('Toluca');
Mensajes: 1.127
Antigüedad: 13 años, 6 meses
Puntos: 511
Pregunta Problema con inicio de sesion

buenos dias necesito ayuda con el inicio de sesion.

tengo el siguiente codigo en la pagina del formulario.


Código HTML:
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">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Inicio de Sesion</title>
  5. </head>
  6. <link type="text/css" rel="stylesheet" href="estilos/estilos.css" />
  7.  
  8. <script type="text/ecmascript" language="javascript">
  9.    
  10.     var cursor;
  11.     if (document.all) {
  12.         cursor='hand';
  13.     } else {
  14.         cursor='pointer';
  15.     }
  16.    
  17.     function valida(){
  18.        
  19.         var mensaj="";
  20.         if(document.getElementById("usu").value=="") mensaj += " Debes de escribir tu nombre de usuario\n ";
  21.         if(document.getElementById("pass").value=="") mensaj += "Debes de escribir tu contraseña ";
  22.        
  23.         if(mensaj != ""){
  24.             alert("" + mensaj);
  25.         }else{
  26.             document.getElementById("frm1").submit();
  27.         }
  28.        
  29.     }
  30.    
  31.  
  32.  
  33.  
  34. <body topmargin="0" leftmargin="0">
  35.     <div align="center">
  36.  
  37.         <form action="login.php" class="aCentro" method="post" name="frm1" id="frm1">
  38.           <table width="327" height="159" border="0" align="center" cellpadding="0" cellspacing="0" style="border-top-color:#CCC">
  39.             <tr class="cabeceraTabla">
  40.               <td colspan="2">inicio de sesi&Oacute;n</td>
  41.               </tr>
  42.             <tr>
  43.               <td width="165">Usuario</td>
  44.               <td width="166"><label>
  45.                 <input name="usu" type="text" class="cajaMedia" id="usu" />
  46.                 </label></td>
  47.               </tr>
  48.             <tr>
  49.               <td>Password</td>
  50.               <td><label>
  51.                 <input name="pass" type="text" class="comboMedio" id="pass" />
  52.                 </label></td>
  53.               </tr>
  54.             <tr>
  55.               <td colspan="2"> <div align="center"><img src="img/Aceptar.gif" width="100" height="24" onmouseover="style.cursor=cursor" onclick="valida()" /></div></td>
  56.               </tr>
  57.             </table>
  58.         </form>
  59.      
  60. </div>
  61.    
  62. </body>
  63. </html>

y en la de loging el siguiente


Código PHP:
Ver original
  1. <?php
  2.  
  3.     include("conec.php");
  4.     session_start();
  5.     $usu=$_POST['usu'];
  6.     $pass=$_POST['pass'];
  7.  
  8.     $sql="SELECT * FROM usuarios WHERE usuario = '$usu'";
  9.     $query=mysql_query($sql,$conexion);
  10.        
  11.         if(mysql_num_rows($query)==0){
  12.             echo "<script>";
  13.             echo "alert('No existe el usuario introducido')";
  14.             echo "</script>";
  15.             echo "<head><meta http-equiv='refresh' content='0; url=index.php?error=15638'></ head>";
  16.         }else{
  17.             $array=mysql_fetch_array($query);
  18.                 if($array["pass"]== $pass){
  19.                     if($array["tipo"] == "Administrador"){
  20.            
  21.                         $_SESSION["Usuario"]=$usu;
  22.                         $_SESSION["Passw"]=$pass;
  23.                         $_SESSION["pass"]=$array["nombre"];
  24.                         $_SESSION["Empresa"]=$array["empresa"];
  25.                
  26.                     echo "<head><meta http-equiv='refresh' content='0; url=/proyecto/ADMIN/index.php?session=true'></head>";
  27.                     }else{
  28.                         if($array["tipo"] == "Mtto"){
  29.  
  30.                             $_SESSION["Usuario"]=$usu;
  31.                             $_SESSION["Passw"]=$pass;
  32.                             $_SESSION["pass"]=$array["nombre"];
  33.                             $_SESSION["Empresa"]=$array["empresa"];
  34.                    
  35.                         echo "<head><meta http-equiv='refresh' content='0; url=/proyecto/MTTO/index.php?session=true'></head>";
  36.                         }else{
  37.                             if($array["tipo"] == "Visual"){
  38.    
  39.                                 $_SESSION["Usuario"]=$usu;
  40.                                 $_SESSION["Passw"]=$pass;
  41.                                 $_SESSION["pass"]=$array["nombre"];
  42.                                 $_SESSION["Empresa"]=$array["empresa"];
  43.                            
  44.                                 echo "<head><meta http-equiv='refresh' content='0; url=/proyecto/VSL/index.php?session=true'></head>";
  45.  
  46.                             }
  47.                         }
  48.                     }
  49.                    
  50.                 }else{
  51.                     echo "<script>";
  52.                     echo "alert('La contraseña es incorrecta')";
  53.                     echo "</script>";
  54.                     echo "<head><meta http-equiv='refresh' content='0; url=index.php?error=15838'></head>";
  55.                 }  
  56.         }
  57. ?>


y al momento en el que conprueba los datos me da acceso a la pagina la cual deseo pero el probleme es que al comprobar me da el siguiente error:

Notice: A session had already been started - ignoring session_start() in C:\wamp\www\proyecto\login.php on line 4
Call Stack
# Time Memory Function Location
1 0.0008 378808 {main}( ) ..\login.php:0
2 0.0046 385960 session_start ( ) ..\login.php:4


Ademas por otra parte al cerrar sesion e insertar la url de la pagina da acceso sin tener iniciada la sesion aqui les dejo el codigo para que los chequen


pagina de aceptacion de usuario:

Código PHP:
Ver original
  1. <?php
  2.     session_start();
  3.     session_set_cookie_params(0, "/", $_SERVER["HTTP_HOST"], 0);  
  4.         if(!isset($_SESSION)){
  5.             echo "error";
  6.             header("location:../index.php");
  7.         }else{
  8.  
  9. ?>
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml">
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  14. <title>Pagina Princiapal</title>   
  15. </head>
  16. <link href="../estilos/estilos.css" type="text/css" rel="stylesheet" />
  17.  
  18. <body>
  19. pagina del administrador
  20.  
  21. <?php
  22.  echo "<font size=8> Bienvenido: ".$_SESSION["Usuario"]. "</font>";
  23. ?>
  24.  
  25. <a href="../logout.php">cerrar sesion </a>
  26.  
  27. </body>
  28. </html>
  29.  
  30.  
  31. <?php
  32.     }
  33. ?>


y pagina de cerrar sesion :

Código PHP:
Ver original
  1. <?
  2.     session_start();
  3.     if(!isset($_SESSION)){
  4.        
  5.         echo "no hay sesion";
  6.             header("location:index.php");
  7.     } else {
  8.         session_unset();
  9.         session_destroy();
  10.         echo "<head><meta http-equiv='refresh' content='0; url=index.php?sesion=exit'></head>";
  11.        
  12.     }
  13. ?>
  #2 (permalink)  
Antiguo 24/01/2011, 11:24
Avatar de Heli0s  
Fecha de Ingreso: abril-2010
Mensajes: 789
Antigüedad: 14 años
Puntos: 40
Respuesta: Problema con inicio de sesion

En el archivo conec.php tienes un session_start()?

Etiquetas: inicio
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 15:25.