我試圖修改論壇的登錄表單,以便在登錄後,它會去,「歡迎,用戶名」。php - 保存用戶名作爲變量,然後在其他地方回顯
這裏的signin.php內容一大塊 -
if($errors == false){
$user = $db->get_row("SELECT * FROM " . TABLES_PREFIX . "users WHERE email = '" . $_POST['username_or_email'] . "' OR username = '" . $_POST['username_or_email'] . "' ORDER BY id DESC LIMIT 0,1");
if($user AND ($user->password == encode_password($_POST['password']))){
if($user->status == 'pending'){
$layout->AddContentById('alert', $layout->GetContent('alert'));
$layout->AddContentById('alert_nature', ' alert-danger');
$layout->AddContentById('alert_heading', '{{ST:error}}!');
$layout->AddContentById('alert_message', '{{ST:your_account_not_activated}}');
}elseif($user->status == 'banned'){
$layout->AddContentById('alert', $layout->GetContent('alert'));
$layout->AddContentById('alert_nature', ' alert-danger');
$layout->AddContentById('alert_heading', '{{ST:error}}!');
$layout->AddContentById('alert_message', '{{ST:your_account_is_banned}}');
}else{
Users_LoggedIn($user, isset($_POST['remember_me']));
// **I'm guessing this is exactly where I should store the username as var**
header('Location: '.FORUM_URL); // redirects to index.php
exit;
}
}else{
$layout->AddContentById('alert', $layout->GetContent('alert'));
$layout->AddContentById('alert_nature', ' alert-danger');
$layout->AddContentById('alert_heading', '{{ST:error}}!');
$layout->AddContentById('alert_message', '{{ST:the_info_is_not_correct}}');
}
}
而且,當時在我的index.php想我會加上這麼幾行去類似的信息(僞代碼) -
echo '<div id="username">Welcome, '+$USERNAME+'</div>';
我試着玩$ _SESSION ['用戶名'],但我很無用的PHP,所以任何指導將是非常有益的,謝謝。
即C/JS串聯語法''+ $ USERNAME +''你想使用點。 –
http://php.net/manual/en/reserved.variables.session.php –
'Users_LoggedIn()'做了什麼?我想它會保存對用戶的引用,以便在隨後的請求中提供用戶名。試試'print_r($ _ SESSION)'看看它是否在那裏,也許它在$ _SESSION ['user'] ['username']'或類似的東西,或者它只是保存用戶ID,你會需要從數據庫中提取用戶(或修改'Users_LoggedIn()'方法來存儲用戶名)。 – dotcomly