5. User login (login.php)
At the beginning, we said that the entrance to the game is the index.php file; now that we have installed it, we naturally turn to the login process and start watching.
As usual, the previous section is a piece of code that we have introduced in advance, so we will not go into details; the difference is that the language file used is login.mo, and there is a LOGIN constant. As follows
define('INSIDE' , true); define('INSTALL' , false); define('LOGIN' , true); $InLogin = true; $xnova_root_path = './'; include($xnova_root_path . 'extension.inc'); include($xnova_root_path . 'common.' . $phpEx); includeLang('login');
Next is the structure we talked about before. The branch we entered for the first time is the following code:
$parse = $lang; $Count = doquery('SELECT COUNT(*) as `players` FROM {{table}} WHERE 1', 'users', true); $LastPlayer = doquery('SELECT `username` FROM {{table}} ORDER BY `register_time` DESC', 'users', true); $parse['last_user'] = $LastPlayer['username']; $PlayersOnline = doquery("SELECT COUNT(DISTINCT(id)) as `onlinenow` FROM {{table}} WHERE `onlinetime` > '" . (time()-900) ."';", 'users', true); $parse['online_users'] = $PlayersOnline['onlinenow']; $parse['users_amount'] = $Count['players']; $parse['servername'] = $game_config['game_name']; $parse['forum_url'] = $game_config['forum_url']; $parse['PasswordLost'] = $lang['PasswordLost']; $page = parsetemplate(gettemplate('login_body'), $parse); // Test pour prendre le nombre total de joueur et le nombre de joueurs connect閟 if ($_GET['ucount'] == 1) { $page = $PlayersOnline['onlinenow']."/".$Count['players']; die ( $page ); } else { display($page, $lang['Login']); }
Mainly to obtain the number of registered users, the last registered users, and the current number of online users; and display the login welcome page, including the user data obtained previously.
Okay, now the user can choose to register and go to the previous chapter process, or enter the username and password to go to the login process.
1. First obtain the user’s record from the database based on the entered user
2. If there is a record, use md5 to determine whether the user’s password is correct
3. If the password is correct, check whether the user has selected the remember password function, which will be used later
4. include database configuration file config
5. Setcookie, which contains username, password, etc.
6. Redirect to frames.php file
If the first few judgments are correct, some error messages will appear and the login process will end. The message() function prompt will be used, as mentioned before.