简体   繁体   English

用于在页面之间保存变量的会话

[英]Session for holding variables between pages

I'm making a logoquiz for my Computer Science class, and I'm busy with a page to register users with an account name and email address. 我正在为我的计算机科学课程制作一个logoquiz,我正忙着用一个页面向用户注册一个帐户名和电子邮件地址。 After successfully registering people will be redirected to index.php 成功注册后,人们将被重定向到index.php

In the page the are redirected to, there is a green box which says that the registration finished, and gives them further instructions. 在重定向到的页面中,有一个绿色框表示注册已完成,并为其提供进一步说明。

When testing, every time I visit index.php, it gives that notice with nothing in the email and username. 在测试时,每次我访问index.php时,它都会在电子邮件和用户名中没有任何通知。

<!--- Notice itself --->
<?php
    session_start();
    if(isset($_SESSION)){
        $email = $_SESSION["email"];
        $username = $_SESSION["username"];
    ?>
<!--- Green box that pops up --->
        <div class="notice success"><i class="icon-ok icon-large"></i> Je registratie is succesvol verzonden <?php echo $username;?><br>
        Er is een email verzonden naar <?php echo $email; ?>.<br>
        Volg de instucties in deze mail om te kunnen beginnen<a href="#close" class="icon-remove"></a></div>

        <?php 
        session_destroy();
        } ?>

In the register page itself (RegSpelers.php), this code is used for the session 在注册页面本身(RegSpelers.php)中,此代码用于会话

<?php }elseif($wrong == FALSE && !empty($_POST)){
    // After checking for wrong entered field or nothing at all use session.
    $_SESSION["email"] = $email;
    $_SESSION["username"] = $username;
    header ('Location: index.php');
    } ?>

Because of 因为

session_start();

The $_SESSION array exists and isset return true. $ _SESSION数组存在且isset返回true。

Now maybe this is what you where looking for 现在也许这就是你在寻找的地方

if(isset($_SESSION['email'])){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM