我试图通过panique使用此php-login-advanced来理解PHP登录系统。 register.php的代码段为:
<?php
// check for minimum PHP version
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
exit('Sorry, this script does not run on a PHP version smaller than 5.3.7 !');
} else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
// if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
// (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
require_once('libraries/password_compatibility_library.php');
}
// include the config
require_once('config/config.php');
// include the to-be-used language, english by default. feel free to translate your project and include something else
require_once('translations/en.php');
// include the PHPMailer library
require_once('libraries/PHPMailer.php');
// load the registration class
require_once('classes/Registration.php');
// create the registration object. when this object is created, it will do all registration stuff automatically
// so this single line handles the entire registration process.
$registration = new Registration();
// showing the register view (with the registration form, and messages/errors)
include("views/register.php");
在类注册中构造函数是:
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"]);
}
}
在行$registration = new Registration();
上创建一个类型为Registration的新对象,并在服务器端调用它的构造函数。服务器调用 session_start()函数。如果客户端发送了有效的会话ID,则会在 $ _ SESSION 变量中加载与该会话ID相对应的文件,否则会生成新的会话ID并将其发送到客户端以将其存储在 COOKIE 维持会话。呈现的register.php页面被发送到客户端。客户填写表格并提交。表单的值存储在服务器端的 $ _ POST 数组中,这次创建类注册的NEW对象时,还会执行其他两行并注册用户。
我的问题是: 我是否正确理解 $ _ POST , $ _ SESSION 和注册对象的生命周期?我们非常欢迎更好的解释。