Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/06/2013, 17:12
Avatar de nexus44
nexus44
 
Fecha de Ingreso: octubre-2012
Ubicación: Piura
Mensajes: 108
Antigüedad: 11 años, 6 meses
Puntos: 1
Respuesta: Ayuda con mi Acceso login

Código PHP:
Ver original
  1. <?php require_once('Connections/con_usuarios.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33. ?>
  34. <?php
  35. // *** Validate request to login to this site.
  36. if (!isset($_SESSION)) {
  37. }
  38.  
  39. $loginFormAction = $_SERVER['PHP_SELF'];
  40. if (isset($_GET['accesscheck'])) {
  41.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  42. }
  43.  
  44. if (isset($_POST['nombre'])) {
  45.   $loginUsername=$_POST['nombre'];
  46.   $password=$_POST['password'];
  47.   $MM_fldUserAuthorization = "control";
  48.   $MM_redirectLoginSuccess = "acceso.php";
  49.   $MM_redirectLoginFailed = "error.php";
  50.   $MM_redirecttoReferrer = false;
  51.   mysql_select_db($database_con_usuarios, $con_usuarios);
  52.    
  53. $LoginRS__query=sprintf("SELECT nombre_user, password, control FROM usuarios WHERE nombre_user=%s AND password=%s",
  54.   GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  55.    
  56.   $LoginRS = mysql_query($LoginRS__query, $con_usuarios) or die(mysql_error());
  57.   $loginFoundUser = mysql_num_rows($LoginRS);
  58.   if ($loginFoundUser) {
  59.     // OK, el usuario existe, hay que verificar los datos:
  60.     // Lees la consulta
  61.     $row = mysql_fetch_assoc($loginFoundUser);
  62.     // Comparas
  63.     if($row['nombre_user'] == $loginUsername || $row['password'] == $password) {
  64.            // OK, los datos son correctos
  65.            //declare two session variables and assign them
  66.            $_SESSION['MM_Username'] = $loginUsername;
  67.            /* ********************** ERROR? ********************************* */
  68.            // Este dato... de dónde salió?, en la consulta solo obtienes nombre_user y password
  69.            $_SESSION['MM_UserGroup'] = $loginStrGroup;  
  70.  
  71.            if (isset($_SESSION['PrevUrl']) && false) {
  72.              $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  73.            }
  74.            header("Location: " . $MM_redirectLoginSuccess );
  75.          }
  76.          else {
  77.            header("Location: ". $MM_redirectLoginFailed );
  78.          }
  79.          // Como hay redirección, es necesario detener el script
  80.          exit;
  81.     }
  82.     // Los datos no son correctos por diferencia entre mayúsculas/minúsculas
  83. }
  84.  
  85. ?>
  86. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  87. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/base.dwt.php" codeOutsideHTMLIsLocked="false" -->
  88. <head>
  89. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  90. <!-- InstanceBeginEditable name="doctitle" -->
  91. <title>.::Bienvenidos::.</title>
  92. <!-- InstanceEndEditable -->
  93. <style type="text/css">
  94. <!--
  95. body {
  96.     margin-top: 0px;
  97.     background-image: url(fondo.jpg);
  98.     background-repeat: repeat-x;
  99. }
  100. -->
  101. </style>
  102. <!-- InstanceBeginEditable name="head" -->
  103. <script type="text/javascript">
  104. <!--
  105. function MM_validateForm() { //v4.0
  106.   if (document.getElementById){
  107.     var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  108.     for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
  109.       if (val) { nm=val.name; if ((val=val.value)!="") {
  110.         if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  111.           if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  112.         } else if (test!='R') { num = parseFloat(val);
  113.           if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  114.           if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  115.             min=test.substring(8,p); max=test.substring(p+1);
  116.             if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  117.       } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  118.     } if (errors) alert('The following error(s) occurred:\n'+errors);
  119.     document.MM_returnValue = (errors == '');
  120. } }
  121. //-->
  122. </script>
  123. <!-- InstanceEndEditable -->
  124. </head>
  125.  
  126. <body>
  127.  
  128.   <tr>
  129.     <td align="center" bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="contenido" -->
  130.      
  131.       <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  132.        <center> <img src="imagenes/entrada1.jpg" width="700" height="200" />       </center>
  133.         <table width="80" border="1" align="center">
  134.           <tr>
  135.             <td><img src="imagenes/nm.jpg" width="96" height="31" /></td>
  136.             <td align="left"><input name="nombre" type="text" id="nombre" size="40" /></td>
  137.           </tr>
  138.           <tr>
  139.             <td><img src="imagenes/cs.jpg" width="92" height="29" /></td>
  140.             <td align="left"><input name="password" type="password" id="password" size="40" /></td>
  141.           </tr>
  142.           <tr>
  143.            
  144.             <td align="center"> <input name="button" type="submit" id="button" onclick="MM_validateForm('nombre','','R','password','','R');return document.MM_returnValue" value="Ingresar" /></td>
  145.           </tr>
  146.         </table>
  147.         <p><a href="nuevo_usuario.php"><img src="imagenes/rfs.jpg" width="233" height="57" align="right" /></a></p>
  148.     </form>
  149. <p><center><img src="imagenes/tds.jpg" width="774" height="243" /></center></p>
  150.  
  151.     <!-- InstanceEndEditable --></td>
  152.   </tr>
  153. </table>
  154. </body>
  155. <!-- InstanceEnd --></html>
__________________

"Nuestra capacidad se aleja de la Humanidad"