我在php

时间:2017-06-13 01:20:09

标签: php file session object state

我从php开始,我希望以登录形式获取会话对象,然后,我希望在php网页中显示对象会话,但会话对象无法读取其值对象。

我的php文件:

try {

   $userLogin = new userDto();
   $userLogin->setUsername($_POST["txtUsername"]);
   $userLogin->setPassword($_POST["txtPassword"]);

   if (UserDao::validateLogin($userLogin)) {  

     //if true, the method validateLogin load other values object in data access layer
     //i tried with print_r($userLogin) and show all values (name,age,ocupation, profile etc....).. works

     session_start();

    if ($userLogin->getIdProfile() == 1) {  

        $_SESSION["userClient"] = $userLogin;
        include_once '../Pages/MenuClient.php';
    } else {
        $_SESSION['adminUser'] = $userLogin;
        include_once '../Paginas/MenuAdmin.php';
    }
} else {
    echo 'No exist';
}

} catch (Exception $ex) {
   echo $ex->getMessage();
}

php网页:

  <?php

    include_once '../../Dto/UserDto.php';

     $dto = new UserDto();
     if(isset($_SESSION["userClient"])) {
         $dto = $_SESSION["userClient"];
         echo 'Exist user'; --> works!!
         echo '<script type="text/javascript">alert("'+$dto->getName()+'");</script>';  --> not work
     else {
            echo '<script type="text/javascript">alert("no found");</script>';
     }
    ?>

    <label><?php echo $dto->getName()?></label>   --> not work
    <label value="<?php echo $dto->getName()?>"></label>  --> not work

0 个答案:

没有答案