Ver Mensaje Individual
  #13 (permalink)  
Antiguo 19/12/2004, 03:35
mauriciomro
 
Fecha de Ingreso: julio-2004
Mensajes: 9
Antigüedad: 19 años, 9 meses
Puntos: 0
Exclamación Nueva manera..pero todavia se pierde los valores

ahor estoy haciendo de una nueva manera lo de sesiones ,pero aun asi se pierde el valor, aki les va el codigo para ver si pueden ver donde me ekivoco
clase sesion
Código PHP:
class Session {
    
/**
     * Initialize the session to make sure the lockList is present and
     * unwritable
     **/
    
function __construct() {
        if (!
$this->isSess("lockList")) {
            
$lockList = array();
            
$lockList[] = "lockList";
            
$_SESSION["lockList"] = $lockList;
        }
    }

    
/**
     * Sets a value in the session, checking first to make sure the 
     * variable isn't locked and the name is valid.
     * @param string $name name of variable stored in session
     * @param mixed $value value of variable stored in session
     **/
    
function setSess($name$value)
    {
        if (
preg_match("!^[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*$!i"$name)){
            
$lockList $this->getSess("lockList");
            if (
in_array($name$lockList)) {
                
trigger_error("'<i>$name</i>' is locked and cannot be set"E_USER_NOTICE);
            } else {
                
$_SESSION[$name] = $value;
            }
        } else {
            
trigger_error("Invalid variable name"E_USER_NOTICE);
        }
    }

    
/**
     * Gets a value from session
     * @param string $name nmae of variable checked in session
     * @return mixed Value in session or null if not found
     **/
    
function getSess($name)
    {
        if (isset(
$_SESSION[$name])) {
            return 
$_SESSION[$name];
        } else {
            return 
null;    
        }
    }

    
/**
     * Checks to see if a variable is in session
     * @param string $name name of variable checked in session
     * @return boolean true if found, false if not
     **/
    
function isSess($name)
    {
        return (
$this->getSess($name) !== null);
    }

    
/**
     * Delete a key/value pair in session, checking first to make sure 
     * the key is not locked.
     * @param string $name name of variable to be removed from session
     **/
    
function delSess($name)
    {
        
$lockList $this->getSess("lockList");
        if (
in_array($name$lockList)) {
            
trigger_error("'<i>$name</i>' is locked and cannot be deleted"E_USER_NOTICE);
        } else {
            unset(
$_SESSION[$name]);        
        }
    }

    
/**
     * Locks a key/value pair in the session so that it cannot be overwritten
     * @param string $name name of the variable to be locked in session
     **/
    
function lockSess($name)
    {
        
$lockList $this->getSess("lockList");
        if (
$this->isSess($name)) {
            if (
in_array($name$lockList)) {
                
trigger_error("'<i>$name</i>' has already been locked"E_USER_NOTICE);
            } else {
                
$lockList[] = $name;
                
$_SESSION["lockList"] = $lockList;
            }
        } else {
            
trigger_error("There is no session variable called '<i>$name</i>'"E_USER_NOTICE);
        }
    }

    
/**
     * Unlocks a key/value parin in the session so that it can be updated
     * @param string $name name of variable to be unlocked in session.
     * @return 
     **/
    
function unlockSess($name)
    {
        
$lockList $this->getSess("lockList");
        if (
$key array_search($name$lockList)) {
            unset(
$lockList[$key]);
            
$_SESSION["lockList"] = $lockList;
        } else {
            
trigger_error("'<i>$name</i>' is not locked."E_USER_NOTICE);
        }
    }

    
/**
     * Kills the entire session. This is VERY dangerous to use. Use with caution!
     **/
    
function killSess()
    {
        
session_destroy();
        
$_SESSION = array();
    }
}
?> 
codigo carga sesion(control.php)


Código PHP:
require_once("session.class.php");
$session = new Session();

require_once(
"./ClaseSesion.php");
$sesion = new Sesiones();

$user $sesion->VerificarTipoUsuario($_POST['login']);
$login $_POST['login'];
$contra $_POST['contra'];

switch (
$user) {
    case 
"alumno":
        
$documento "../data/usuarios/alumnos.xml";
        
$id "matricula";
        break;
    case 
"profesor":
        
$documento "../data/usuarios/profesores.xml";
        
$id "rut";
        break;
    case 
"admin":
        
$documento "../admin/xml/admin.xml";
           
$id "id";
        break;
}

// se carga el documento con los usuarios del tipo de quien hizo login
$xml simplexml_load_file($documento);

foreach (
$xml->$user as $archivo){
       if (
strtolower($archivo->$id) == strtolower($login)) { // $id y $login: matricula
           
if (strtolower($contra) == strtolower($archivo->password)) {
            
$session->setSess('autorizado''SI');
            
$session->setSess("user"$user);
            
$session->setSess("login"$login);
            
$session->setSess('carrera',  $archivo->carrera);
            
$session->setSess('asignaturas',  $archivo->asignaturas);
               
$session->setSess("nombres"$archivo->nombres);
               
$session->setSess("paterno"$archivo->paterno);
        }
    }
    
}
?> 
cdigo para verificar la sesion y es aki donde lo generado se pierde,que se supone ke deveria venir lo de sesiones de la pagina anterior

Código PHP:
<?php
include_once "session.class.php";
$session = new Session();
session_start();
$mm=$session->getSess("login");
?>
por favor ayudenme con esto pk es de vital importancia.....muchas gracias