Ver Mensaje Individual
  #8 (permalink)  
Antiguo 09/06/2011, 07:26
magotas
 
Fecha de Ingreso: mayo-2010
Ubicación: Madrid
Mensajes: 74
Antigüedad: 14 años
Puntos: 0
Respuesta: Pasar dato a una variable global

El código de la página de login. Lo importante está de la linea 54 a la 64.

Código PHP:
Ver original
  1. <?php require_once('Connections/incid_preventiva.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['caja_usuario'])) {
  45.   $loginUsername=$_POST['caja_usuario'];
  46.   $password=$_POST['caja_contrasenia'];
  47.   $MM_fldUserAuthorization = "";
  48.   $MM_redirectLoginSuccess = "gestion/ges_inci_nuevos.php";
  49.   $MM_redirectLoginFailed = "login.php";
  50.   $MM_redirecttoReferrer = false;
  51.   mysql_select_db($database_incid_preventiva, $incid_preventiva);
  52.  
  53.   $LoginRS__query=sprintf("SELECT LOGIN, CONTRASENA, ID_USUARIO FROM usuarios WHERE LOGIN=%s AND CONTRASENA=%s",
  54.     GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  55.    
  56.   $LoginRS = mysql_query($LoginRS__query, $incid_preventiva) or die(mysql_error());
  57.   $loginFoundUser = mysql_num_rows($LoginRS);
  58.   if ($loginFoundUser) {
  59.      $loginStrGroup = "";
  60.    
  61.     if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
  62.     //declare two session variables and assign them
  63.     $_SESSION['MM_Idusuario'] = $row['ID_USUARIO'];
  64.     $_SESSION['MM_Username'] = $loginUsername;
  65.     $_SESSION['MM_UserGroup'] = $loginStrGroup;      
  66.  
  67.     if (isset($_SESSION['PrevUrl']) && false) {
  68.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
  69.     }
  70.     header("Location: " . $MM_redirectLoginSuccess );
  71.   }
  72.   else {
  73.     header("Location: ". $MM_redirectLoginFailed );
  74.   }
  75. }
  76. ?>
  77. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  78. <html xmlns="http://www.w3.org/1999/xhtml">
  79. <head>
  80. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  81. <title>Documento sin tÃ*tulo</title>
  82. <link href="estilos.css" rel="stylesheet" type="text/css" />
  83. </head>
  84.  
  85. <body>
  86. <table width="100%" border="0" align="center">
  87.   <tr>
  88.     <td><table width="95%" border="0" align="center">
  89.       <tr>
  90.         <td><img src="imagenes/logo_cabecera.gif" alt="" width="425" height="58" /></td>
  91.       </tr>
  92.       <tr>
  93.         <td><table width="95%" border="0" align="center">
  94.           <tr align="center">
  95.             <td class="tabla_cabecera">Verificación de acceso a Gestión de Incidentes</td>
  96.           </tr>
  97.         </table>
  98.           <form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
  99.             <table width="50%" border="0" align="center" class="table_centrada_azul">
  100.               <tr align="center">
  101.                 <td>&nbsp;</td>
  102.               </tr>
  103.               <tr align="center">
  104.                 <td>Usuario</td>
  105.               </tr>
  106.               <tr align="center">
  107.                 <td><label for="caja_usuario"></label>
  108.                   <input type="text" name="caja_usuario" id="caja_usuario" /></td>
  109.               </tr>
  110.               <tr align="center">
  111.                 <td>Contraseña</td>
  112.               </tr>
  113.               <tr align="center">
  114.                 <td><label for="caja_contrasenia"></label>
  115.                   <input type="password" name="caja_contrasenia" id="caja_contrasenia" /></td>
  116.               </tr>
  117.               <tr align="center">
  118.                 <td>&nbsp;</td>
  119.               </tr>
  120.               <tr align="center">
  121.                 <td><input type="submit" name="boton_enviar" id="boton_enviar" value="Enviar" /></td>
  122.               </tr>
  123.               <tr align="center">
  124.                 <td>&nbsp;</td>
  125.               </tr>
  126.             </table>
  127.           </form>
  128.           <p>&nbsp;</p>
  129.           <p>&nbsp;</p></td>
  130.       </tr>
  131.     </table></td>
  132.   </tr>
  133. </table>
  134. </body>
  135. </html>

Y en esta está cómo trato de recoger el dato. Quitando que os dejo el comienzo para que se vea que aparece el session_start() lo interesante es lo último.

Código PHP:
Ver original
  1. <?php require_once('../Connections/incid_preventiva.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.  
  35. .
  36. .
  37. .
  38.  
  39.  
  40. <body>
  41. <input name="REVISOR" type="" id="REVISOR" value="<?php echo $_SESSION['MM_Username']; ?>" />
  42. <input name="REVISOR" type="" id="REVISOR" value="<?php echo $_SESSION['MM_Idusuario']; ?>" />
  43.  
  44. </body>

Con esto lo que consigo es que en una caja veo el contenido de la variable MM_Username pero en la otra no consigo nada