Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/07/2012, 01:04
Avatar de evairdesign
evairdesign
 
Fecha de Ingreso: abril-2012
Mensajes: 54
Antigüedad: 12 años
Puntos: 7
Me ayudan a entender este codigo generado por dreamweaver

Hola! por favor me ayudarian a comprender el siguiente codigo generado por dreamweaver para crear el inicio de sesion de un usuario.

Yo pondre lo que entiendo, si esta mal, por favor diganmelo y si pueden agregar información y responder mis dudas, exelente

En el codigo estan mis dudas, en forma de comentario, muchas gracias
Código PHP:
Ver original
  1. <?php
  2. // Se llama al archivo wamp_login que contiene los datos para crear conexion con la bd
  3.  require_once('Connections/wamp_login.php');
  4.  ?>
  5.  
  6. <?php
  7. // Funcion que extrae el texto de una variable...aqui tengo mis dudas, no estoy seguro de que esa se la principal funcion
  8. if (!function_exists("GetSQLValueString")) {
  9. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  10. {
  11.   if (PHP_VERSION < 6) {
  12.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  13.   }
  14.  
  15.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  16.  
  17.   switch ($theType) {
  18.     case "text":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;    
  21.     case "long":
  22.     case "int":
  23.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  24.       break;
  25.     case "double":
  26.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  27.       break;
  28.     case "date":
  29.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  30.       break;
  31.     case "defined":
  32.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  33.       break;
  34.   }
  35.   return $theValue;
  36. }
  37. }
  38. ?>
  39. <?php
  40. // Se crea la sesion que identifica al usuario.
  41. if (!isset($_SESSION)) {
  42. }
  43.  
  44. // recibe el action del formulario y lo identifica como la misma direccion que se esta usando actualmente con ['PHP_SELF']
  45. $loginFormAction = $_SERVER['PHP_SELF'];
  46.  
  47. // Aqui no entiendo que es $_GET['accesscheck'] ¿me podria alguien decir de donde sale eso?
  48. if (isset($_GET['accesscheck'])) {
  49.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  50. }
  51.  
  52. if (isset($_POST['inputUser'])) {
  53.   $loginUsername=$_POST['inputUser'];
  54.   $password=$_POST['inputPass'];
  55.   $MM_fldUserAuthorization = "";
  56.   $MM_redirectLoginSuccess = "usuario.php";
  57.   $MM_redirectLoginFailed = "404";
  58.   $MM_redirecttoReferrer = false;
  59.   mysql_select_db($database_wamp_login, $wamp_login);
  60.  
  61.   $LoginRS__query=sprintf("SELECT tableUsuario, tablePassword FROM tmp_login WHERE tableUsuario=%s AND tablePassword=%s",
  62.  
  63. // ¿que hace la funcion GetSQLValueString especificamente en esta parte? ¿sacar el nombre de usuario del input? si es asi porque se pone como parte de la sentencia SQL
  64.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  65.    
  66.   $LoginRS = mysql_query($LoginRS__query, $wamp_login) or die(mysql_error());
  67.   $loginFoundUser = mysql_num_rows($LoginRS);
  68.   if ($loginFoundUser) {
  69.      $loginStrGroup = "";
  70.    
  71.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  72.     //declare two session variables and assign them
  73.     $_SESSION['MM_Username'] = $loginUsername;
  74.     $_SESSION['MM_UserGroup'] = $loginStrGroup;      
  75.  
  76.     if (isset($_SESSION['PrevUrl']) && false) {
  77.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
  78.     }
  79.  
  80.     header("Location: " . $MM_redirectLoginSuccess );
  81.   }
  82.   else {
  83.     header("Location: ". $MM_redirectLoginFailed );
  84.   }
  85. }
  86.  
  87. ?>
  88. <!doctype html>
  89. <html>
  90. <head>
  91. <meta charset="utf-8">
  92. <title>..::Viden::.. Colegios en Chile</title>
  93. </head>
  94.  
  95. <body>
  96. <form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  97.   <p>
  98.     <label for="textfield">Usuario:</label>
  99.     <input type="text" name="inputUser" id="textfield">
  100.   </p>
  101.   <p>
  102.     <label for="textfield2">Password:</label>
  103.     <input type="text" name="inputPass" id="textfield2">
  104.   </p>
  105.   <p>
  106.     <input type="submit" name="button" id="button" value="Iniciar Sesión">
  107.   </p>
  108. </form>
  109. </body>
  110. </html>
__________________
Todo debe hacerse lo más simple posible pero no más simple