在这个php示例中创建的类实例在哪里?

时间:2015-07-12 12:47:07

标签: php class login instance

我对PHP很陌生,但习惯于其他一些编程语言(例如JAVA,Python)。最近我仔细研究了Login-Script panique / php-login-advanced(https://github.com/panique/php-login-advanced),我发现这是学习一些有用的PHP结构的好方法。

不幸的是有一件事,我不明白,这让我很头疼:所有这些都是从" index.php" whih包括" login_manager.php" (其中包括使用" classes / Login.php")创建一个新的Login-instance。

// create a login object. when this object is created, it will do all login/logout stuff automatically
// so this single line handles the entire login process.
$login = new Login();

如果您尚未登录,则可以自行注册,这会引导您进入" views / register.php"。在这个文件中有一个POST表单,再次调用同一个文件:

<?php include('_header.php'); ?>

<!-- show registration form, but only if we didn't submit already -->
<?php if (!$registration->registration_successful && !$registration->verification_successful) { ?>
<form method="post" action="register.php" name="registerform">
    <label for="user_name"><?php echo WORDING_REGISTRATION_USERNAME; ?></label>
    <input id="user_name" type="text" pattern="[a-zA-Z0-9]{2,64}" name="user_name" required />

    <label for="user_email"><?php echo WORDING_REGISTRATION_EMAIL; ?></label>
    <input id="user_email" type="email" name="user_email" required />

    <label for="user_password_new"><?php echo WORDING_REGISTRATION_PASSWORD; ?></label>
    <input id="user_password_new" type="password" name="user_password_new" pattern=".{6,}" required autocomplete="off" />

    <label for="user_password_repeat"><?php echo WORDING_REGISTRATION_PASSWORD_REPEAT; ?></label>
    <input id="user_password_repeat" type="password" name="user_password_repeat" pattern=".{6,}" required autocomplete="off" />

    <img src="tools/showCaptcha.php" alt="captcha" />

    <label><?php echo WORDING_REGISTRATION_CAPTCHA; ?></label>
    <input type="text" name="captcha" required />

    <input type="submit" name="register" value="<?php echo WORDING_REGISTER; ?>" />
</form>
<?php } ?>

    <a href="index.php"><?php echo WORDING_BACK_TO_LOGIN; ?></a>

<?php include('_footer.php'); ?>

现在我不明白这个$注册实例的来源?!当然它应该是&#34; classes / Registration.php&#34;的一个实例。这解释了使用类的构造函数进一步处理:

public function __construct()
    {
        session_start();

        // if we have such a POST request, call the registerNewUser() method
        if (isset($_POST["register"])) {
            $this->registerNewUser($_POST['user_name'], $_POST['user_email'], $_POST['user_password_new'], $_POST['user_password_repeat'], $_POST["captcha"]);
        // if we have such a GET request, call the verifyNewUser() method
        } else if (isset($_GET["id"]) && isset($_GET["verification_code"])) {
            $this->verifyNewUser($_GET["id"], $_GET["verification_code"]);
        }
    }

但这里的连接在哪里?我搜索了整个项目的所有文件,我找不到类似&#34;新注册()&#34;甚至没有设置$ registration变量(据我所知)。因此,当脚本没有问题时,需要一些我不知道的技巧。

我还以为它可以设置在&#34; _header.php&#34;但是在这个文件中只有一些错误输出:

// show potential errors / feedback (from registration object)
if (isset($registration)) {
    if ($registration->errors) {
        foreach ($registration->errors as $error) {
            echo $error;
        }
    }
    if ($registration->messages) {
        foreach ($registration->messages as $message) {
            echo $message;
        }
    }
}

0 个答案:

没有答案