I'm quite new to PHP but used to some other programming languages (e.g JAVA,Python). Recently I had a closer look to the Login-Script panique/php-login-advanced (https://github.com/panique/php-login-advanced) which I find is a really good way to learn some useful PHP-structures.
Unfortunately there is one thing, i don't understand and which gives me quite a headache: all starts from "index.php" whih includes "login_manager.php" (used, among others, to create a new Login-instance from "classes/Login.php").
// 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();
If you aren't logged in, you can register yourself, which leads you to "views/register.php". In this file there is a POST-form, calling the same file again:
<?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'); ?>
Now I don't understand where this $registration instance comes from?! Of course it should be an instance of "classes/Registration.php" which explains the further processing using the constructor of the class:
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"]);
}
}
But where is the connection here? I searched the complete project with all files and I could not find something like "new Registration()" and even the $registration variable is never set (to my knowledge). So as the script works without problems, there needs to be some trick i don't know.
I also thought it could be set in the "_header.php" but in this file there is only some error-output:
// 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;
}
}
}