Foros del Web » Programando para Internet » PHP »

Formulario usuario y password

Estas en el tema de Formulario usuario y password en el foro de PHP en Foros del Web. Hola a todos: Tengo 2 formularios. En el 1º, el usuario introduce su nombre de usuario y password (lo que le permite ir al 2º ...
  #1 (permalink)  
Antiguo 02/11/2011, 19:28
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 13 años, 9 meses
Puntos: 4
Formulario usuario y password

Hola a todos:

Tengo 2 formularios.

En el 1º, el usuario introduce su nombre de usuario y password (lo que le permite ir al 2º formulario).

En el 2º, se muestra el contenido de varios campos de una base de datos.

Me gustaría que en el segundo formulario, se muestre solo la información del usuario que accede a ella.

Muchas gracias.

Código PHP:
Ver original
  1. <?php require_once('../Connections/contactos.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. mysql_select_db($database_contactos, $contactos);
  35. $query_usuar = "SELECT * FROM contactos ORDER BY fechaentrada DESC";
  36. $usuar = mysql_query($query_usuar, $contactos) or die(mysql_error());
  37. $row_usuar = mysql_fetch_assoc($usuar);
  38. $totalRows_usuar = mysql_num_rows($usuar);
  39. ?>
  40. <?php
  41. // *** Validate request to login to this site.
  42. if (!isset($_SESSION)) {
  43. }
  44.  
  45. $loginFormAction = $_SERVER['PHP_SELF'];
  46. if (isset($_GET['accesscheck'])) {
  47.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  48. }
  49.  
  50. if (isset($_POST['usuario'])) {
  51.   $loginUsername=$_POST['usuario'];
  52.   $password=$_POST['contrasenya'];
  53.   $MM_fldUserAuthorization = "";
  54.   $MM_redirectLoginSuccess = "anuncio_usuario.php";  
  55.   $MM_redirectLoginFailed = "usuario_error.php";
  56.   $MM_redirecttoReferrer = false;
  57.   mysql_select_db($database_contactos, $contactos);
  58.  
  59.   $LoginRS__query=sprintf("SELECT nombre_usuario, password FROM contactos WHERE nombre_usuario=%s AND password=%s",
  60.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  61.    
  62.   $LoginRS = mysql_query($LoginRS__query, $contactos) or die(mysql_error());
  63.   $loginFoundUser = mysql_num_rows($LoginRS);
  64.   if ($loginFoundUser) {
  65.      $loginStrGroup = "";
  66.    
  67.     //declare two session variables and assign them
  68.     $_SESSION['MM_Username'] = $loginUsername;
  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. }
  80. ?>
  81.  
  82. ...
  83.  
  84. <form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  85. <p align="left"><strong>Usuario:</strong>    
  86.   <input type="text" name="usuario" id="usuario" />
  87. </p>
  88.           <p align="left"><strong>Contrase&ntilde;a:</strong>
  89.             <input name="contrasenya" type="password" id="contrasenya" size="19" />
  90.           </p>
  91.           <p align="left">
  92.         <input type="submit" name="button" id="button" value="Entrar" /></p></form></div>
  93.       <p align="right" style="color: #00F; font-weight: bold;">&nbsp;</p>
  94.     </div>
  95.     <div align="center"></div>
  96. </div>
  97.   <!-- end #container -->
  98. </div>
  99. </body>
  100. </html>
  101. <?php
  102. ?>
  #2 (permalink)  
Antiguo 02/11/2011, 19:30
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 13 años, 9 meses
Puntos: 4
Respuesta: Formulario usuario y password

2º Formulario (anuncio_usuario.php)

Código PHP:
Ver original
  1. once('../Connections/contactos.php'); ?>
  2. <?php
  3. if (!isset($_SESSION)) {
  4. }
  5. $MM_authorizedUsers = "";
  6. $MM_donotCheckaccess = "true";
  7.  
  8. // *** Restrict Access To Page: Grant or deny access to this page
  9. function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
  10.   // For security, start by assuming the visitor is NOT authorized.
  11.   $isValid = False;
  12.  
  13.   // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  14.   // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  15.   if (!empty($UserName)) {
  16.     // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
  17.     // Parse the strings into arrays.
  18.     $arrUsers = Explode(",", $strUsers);
  19.     $arrGroups = Explode(",", $strGroups);
  20.     if (in_array($UserName, $arrUsers)) {
  21.       $isValid = true;
  22.     }
  23.     // Or, you may restrict access to only certain users based on their username.
  24.     if (in_array($UserGroup, $arrGroups)) {
  25.       $isValid = true;
  26.     }
  27.     if (($strUsers == "") && true) {
  28.       $isValid = true;
  29.     }
  30.   }
  31.   return $isValid;
  32. }
  33.  
  34. $MM_restrictGoTo = "usuario.php";
  35. if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {  
  36.   $MM_qsChar = "?";
  37.   $MM_referrer = $_SERVER['PHP_SELF'];
  38.   if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  39.   if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
  40.   $MM_referrer .= "?" . $QUERY_STRING;
  41.   $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  42.   header("Location: ". $MM_restrictGoTo);
  43.   exit;
  44. }
  45. ?>
  46. <?php
  47. if (!function_exists("GetSQLValueString")) {
  48. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  49. {
  50.   if (PHP_VERSION < 6) {
  51.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  52.   }
  53.  
  54.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  55.  
  56.   switch ($theType) {
  57.     case "text":
  58.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  59.       break;    
  60.     case "long":
  61.     case "int":
  62.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  63.       break;
  64.     case "double":
  65.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  66.       break;
  67.     case "date":
  68.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  69.       break;
  70.     case "defined":
  71.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  72.       break;
  73.   }
  74.   return $theValue;
  75. }
  76. }
  77.  
  78. $currentPage = $_SERVER["PHP_SELF"];
  79.  
  80. $maxRows_usuar = 6;
  81. $pageNum_usuar = 0;
  82. if (isset($_GET['pageNum_usuar'])) {
  83.   $pageNum_usuar = $_GET['pageNum_usuar'];
  84. }
  85. $startRow_usuar = $pageNum_usuar * $maxRows_usuar;
  86.  
  87. $colname_usuar = "-1";
  88. if (isset($_SESSION['idempleado'])) {
  89.   $colname_usuar = $_SESSION['idempleado'];
  90. }
  91. mysql_select_db($database_contactos, $contactos);
  92. $query_usuar = sprintf("SELECT * FROM contactos WHERE idempleado = %s ORDER BY fechaentrada DESC", GetSQLValueString($colname_usuar, "int"));
  93. $query_limit_usuar = sprintf("%s LIMIT %d, %d", $query_usuar, $startRow_usuar, $maxRows_usuar);
  94. $usuar = mysql_query($query_limit_usuar, $contactos) or die(mysql_error());
  95. $row_usuar = mysql_fetch_assoc($usuar);
  96.  
  97. if (isset($_GET['totalRows_usuar'])) {
  98.   $totalRows_usuar = $_GET['totalRows_usuar'];
  99. } else {
  100.   $all_usuar = mysql_query($query_usuar);
  101.   $totalRows_usuar = mysql_num_rows($all_usuar);
  102. }
  103. $totalPages_usuar = ceil($totalRows_usuar/$maxRows_usuar)-1;
  104.  
  105. $queryString_usuar = "";
  106. if (!empty($_SERVER['QUERY_STRING'])) {
  107.   $params = explode("&", $_SERVER['QUERY_STRING']);
  108.   $newParams = array();
  109.   foreach ($params as $param) {
  110.     if (stristr($param, "pageNum_usuar") == false &&
  111.         stristr($param, "totalRows_usuar") == false) {
  112.       array_push($newParams, $param);
  113.     }
  114.   }
  115.   if (count($newParams) != 0) {
  116.     $queryString_usuar = "&" . htmlentities(implode("&", $newParams));
  117.   }
  118. }
  119. $queryString_usuar = sprintf("&totalRows_usuar=%d%s", $totalRows_usuar, $queryString_usuar);
  120. ?>
  121.  
  122. ...
  123.  
  124.       </p>
  125. <p>&nbsp;</p>
  126.     </div>
  127.   </div>
  128.   <div id="mainContent">
  129. <div align="center">
  130.       <table width="696" border="0">
  131.         <tr>
  132.           <td height="28" colspan="2" bgcolor="#006699"><div align="center"><strong>Referencia</strong></div></td>
  133.           <td colspan="3" bgcolor="#006699"><div align="left"><strong> Tipo zapato</strong></div></td>
  134.         </tr>
  135.         <?php do { ?>
  136.           <tr>
  137.             <td width="57" rowspan="2" bgcolor="#CCCCCC" style="color: #000"><div align="center"><?php echo $row_usuar['idempleado']; ?></div></td>
  138.             <td width="46" rowspan="2" bgcolor="#CCCCCC" style="color: #000"><div align="center"><a href="<?php echo $row_usuar['foto1']; ?><? echo $registro['img']; ?>" target="_blank"><img src="<?php echo $row_usuar['foto1']; ?><? echo $registro['img']; ?>" alt="foto usuario" width="37" height="35" border="0" /></a></div></td>
  139.             <td colspan="3" bgcolor="#CCCCCC" style="color: #000; font-weight: bold;"><div align="left"> <?php echo $row_usuar['tituloanuncio']; ?></div>              <div align="center"></div></td>
  140.           </tr>
  141.           <tr>
  142.             <td width="428" bgcolor="#CCCCCC" style="color: #000"><div align="left" style="font-size: x-small"> Publicado el <?php echo $row_usuar['fechaentrada']; ?></div></td>
  143.             <td width="77" bgcolor="#CCCCCC" style="color: #000"><div align="center">modificar</div></td>
  144.             <td width="66" bgcolor="#CCCCCC"><div align="center"><a href="anuncio_eliminar_confirmar.php?cod=<?php echo $row_usuar['idempleado']; ?>">eliminar</a></div></td>
  145.           </tr>
  146.           <tr>
  147.             <td colspan="2" style="color: #000">&nbsp;</td>
  148.             <td style="color: #000">&nbsp;</td>
  149.             <td style="color: #000">&nbsp;</td>
  150.             <td>&nbsp;</td>
  151.           </tr>
  152.           <?php } while ($row_usuar = mysql_fetch_assoc($usuar)); ?>
  153.       </table>
  154.     </div>
  155.     <div align="center"></div>
  156.     <div align="center">
  157.       <div align="center" style="font-size: small">
  158.         <p>Registros <?php echo ($startRow_usuar + 1) ?> a <?php echo min($startRow_usuar + $maxRows_usuar, $totalRows_usuar) ?> de <?php echo $totalRows_usuar ?></p>
  159.       </div>
  160. <table border="0">
  161.         <tr>
  162.           <td><?php if ($pageNum_usuar > 0) { // Show if not first page ?>
  163.               <a href="<?php printf("%s?pageNum_usuar=%d%s", $currentPage, 0, $queryString_usuar); ?>"><img src="First.gif" border="0" /></a>
  164.           <?php } // Show if not first page ?></td>
  165.           <td><?php if ($pageNum_usuar > 0) { // Show if not first page ?>
  166.               <a href="<?php printf("%s?pageNum_usuar=%d%s", $currentPage, max(0, $pageNum_usuar - 1), $queryString_usuar); ?>"><img src="Previous.gif" border="0" /></a>
  167.           <?php } // Show if not first page ?></td>
  168.           <td><?php if ($pageNum_usuar < $totalPages_usuar) { // Show if not last page ?>
  169.               <a href="<?php printf("%s?pageNum_usuar=%d%s", $currentPage, min($totalPages_usuar, $pageNum_usuar + 1), $queryString_usuar); ?>"><img src="Next.gif" border="0" /></a>
  170.           <?php } // Show if not last page ?></td>
  171.           <td><?php if ($pageNum_usuar < $totalPages_usuar) { // Show if not last page ?>
  172.               <a href="<?php printf("%s?pageNum_usuar=%d%s", $currentPage, $totalPages_usuar, $queryString_usuar); ?>"><img src="Last.gif" border="0" /></a>
  173.           <?php } // Show if not last page ?></td>
  174.         </tr>
  175.       </table>
  176. <p align="right" style="color: #00F; font-weight: bold;">&nbsp;</p>
  177.     </div>
  178.     <div align="center"></div>
  179. </div>
  180.   <!-- end #container -->
  181. </div>
  182. </body>
  183. </html>
  184. <?php
  185. ?>

Etiquetas: formulario, html, mysql, password, sql, variables, usuarios
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 05:02.