Ver Mensaje Individual
  #28 (permalink)  
Antiguo 13/05/2011, 18:03
djmkmix
 
Fecha de Ingreso: abril-2011
Ubicación: Baja California sur
Mensajes: 39
Antigüedad: 13 años
Puntos: 0
Respuesta: mysql_fetch_array():

Aquí, dice que requiere la conexion a la base de datos osea el archivo, este codigo restringe el acceso a personas, solo miembros de la pagina, ademas de eso es el codigo del log out.

Código PHP:
Ver original
  1. <?php require_once('../../Connections/basededatos.php');
  2.  
  3.  
  4.  
  5. //initialize the session
  6. if (!isset($_SESSION)) {
  7. }
  8.  
  9. // ** Logout the current user. **
  10. $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  11. if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  12.   $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
  13. }
  14.  
  15. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  16.   //to fully log out a visitor we need to clear the session varialbles
  17.   $_SESSION['MM_Username'] = NULL;
  18.   $_SESSION['MM_UserGroup'] = NULL;
  19.   $_SESSION['PrevUrl'] = NULL;
  20.   unset($_SESSION['MM_Username']);
  21.   unset($_SESSION['MM_UserGroup']);
  22.   unset($_SESSION['PrevUrl']);
  23.    
  24.   $logoutGoTo = "../index.php";
  25.   if ($logoutGoTo) {
  26.     header("Location: $logoutGoTo");
  27.     exit;
  28.   }
  29. }
  30.  
  31. //initialize the session
  32. if (!isset($_SESSION)) {
  33. }
  34.  
  35.  
  36. $MM_authorizedUsers = "";
  37. $MM_donotCheckaccess = "true";
  38.  
  39. // *** Restrict Access To Page: Grant or deny access to this page
  40. function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
  41.   // For security, start by assuming the visitor is NOT authorized.
  42.   $isValid = False;
  43.  
  44.   // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  45.   // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  46.   if (!empty($UserName)) {
  47.     // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
  48.     // Parse the strings into arrays.
  49.     $arrUsers = Explode(",", $strUsers);
  50.     $arrGroups = Explode(",", $strGroups);
  51.     if (in_array($UserName, $arrUsers)) {
  52.       $isValid = true;
  53.     }
  54.     // Or, you may restrict access to only certain users based on their username.
  55.     if (in_array($UserGroup, $arrGroups)) {
  56.       $isValid = true;
  57.     }
  58.     if (($strUsers == "") && true) {
  59.       $isValid = true;
  60.     }
  61.   }
  62.   return $isValid;
  63. }
  64.  
  65. $MM_restrictGoTo = "../index.php";
  66. if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {  
  67.   $MM_qsChar = "?";
  68.   $MM_referrer = $_SERVER['PHP_SELF'];
  69.   if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  70.   if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
  71.   $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  72.   $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  73.   header("Location: ". $MM_restrictGoTo);
  74.   exit;
  75. }
  76. ?>




Esté codigo es la consulta e imprime en pantalla el nombre del miembro junto su apellido y el logout

Código PHP:
Ver original
  1. ?php
  2. session_start();
  3. include('../../Connections/basededatos.php');
  4. $result = mysql_query("select * from registro where correo = '$_SESSION[MM_Username]' ",$basededatos);
  5. $row = mysql_fetch_array($result);
  6. $nombre_usuario = ($row["nombre"]);
  7. $apellido_usuario = ($row["apellido"]);
  8. ;?>
  9.  
  10. <h1>Bienvenido</h1>
  11. <h4>
  12. <?php
  13. echo " $nombre_usuario $apellido_usuario ";
  14. mysql_close($basededatos);
  15. ?>
  16. <a href="<?php echo $logoutAction ?>">Desconectar</a>




Esté ultimo hace la conexión a la base de datos y donde estaba el problema
Código PHP:
Ver original
  1. <?php
  2. # FileName="Connection_php_mysql.htm"
  3. # Type="MYSQL"
  4. # HTTP="true"
  5. $hostname_basededatos = "localhost";
  6. $database_basededatos = "clientes";
  7. $username_basededatos = "****";
  8. $password_basededatos = "****";
  9. $basededatos = mysql_pconnect($hostname_basededatos, $username_basededatos, $password_basededatos) or trigger_error(mysql_error(),E_USER_ERROR);
  10. mysql_select_db($database_basededatos, $basededatos);
  11. ?>