注意:未定义的变量:C:\ xampp \ htdocs \ E-Commerce001 \ resources \ components \ registration_form.php在第22行的_SESSION

时间:2018-11-20 19:38:41

标签: session

问题是.i在顶部的user_registration.php文件中启动了会话;

它给我错误“未定义变量_SESSION”,但我在user_registration.php的顶部开始了会话,为什么它给了我该错误

user_registration.php -----文件

$_SESSION['obj_user'] = serialize($obj_user);

if (!empty($errors)) {

    $_SESSION['errors'] = serialize($errors);
    header('Location: '.BASE_VIEWS_URL.'contact.php');
} else {
    try {
        $obj_user->addNewUser();
//        $message['status'] = "User Successfully Registered";
        $_SESSION['status'] = "User Successfully Registered";
        unset($_SESSION['errors']);
        header('Location: '.BASE_VIEWS_URL.'contact.php');
    } catch (Exception $ex) {
        $errors['db'] = $ex->getMessage();
        $_SESSION['errors'] = serialize($errors);
         header('Location: '.BASE_VIEWS_URL.'contact.php');
    }
}

contact.php -----文件代码

<?php
require_once BASE_MODEL_URL . 'user.php';

if (!empty($_SESSION['obj_user'])) {
    $obj_u = unserialize($_SESSION['obj_user']);
} else {
    $obj_u = new User();
}
//    unset($_SESSION['obj_user']);
//    $objuser = $_SESSION['obj_user'];
//    dd($objuser>first_name);
?>
<h2>User Registration Form</h2>
<form method="post" action="<?php echo BASE_CONTROLS_URL ?>user_registration.php" enctype="multipart/form-data">
<?php
$results = array();
if (!empty($_SESSION['errors'])) {
//        dd($_SESSION);
    $results = unserialize($_SESSION['errors']);
//        dd($results);
} else {
    $results['status'] = $_SESSION['status'];
}
?>
    <div class="message">
        <ul>
<?php
foreach ($results as $key => $value) {
    if ($key == 'status') {
        ?>
                    <li class="label label-success"><?php echo $value ?></li>
                    <?php
                } else {
                    ?>

                    <li class="label label-danger"><?php echo $value ?></li>
                    <?php
                }
            }
            ?> 
        </ul>
    </div>

0 个答案:

没有答案