我有一個登錄頁面,它在加載後顯示登錄對話框。登錄對話框只是使用Ajax call
的JQuery
對話框。類似的東西:使用會話cookie生存期和登錄過程進行處理。 PHP
$(function() {
var _width = $.browser.msie ? 316 : 'auto';
var loginDialog = $('#loginDialog');
loginDialog.dialog({
closeOnEscape: false,
open: function() {
$(this).parent().find('.ui-dialog-titlebar-close').hide();
},
resizable: false,
position: 'center',
stack: true,
draggable: false,
height: 'auto',
width: _width,
modal: true,
buttons: {
'submit': function() {
$.ajax({
type: 'post',
dataType: 'html',
url: '/ProjectName/Scripts/php/AccountController.php',
cache: false,
// async: false,
data: $('#loginForm').serialize(),
success: function(accessStatus) {
if(accessStatus === 'granted') {
loginDialog.dialog('close');
}
},
error: function(request, status, error) {
// handle it in a specific manner
alert(error);
}
});
}
}
});
所以如果沒關係(在服務器端)我只是關閉對話框。
然後在AccountController.php
文件作爲現在我有類似的東西:
<?php
session_start();
if(IsAjaxRequest()) {
if(isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
require_once('LDAPHandler.php');
// credentials
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
// ... more parameters
// ... Fetch against AD
if(IsInAdminRole($username, $password)) {
// ... establishing mysql connection & setting connection options
// and then:
mysql_query(
'insert into accounts'.
'(login, sid) values({$username}, {session_id()})'.
'on duplicate key update sid=values(sid)'
);
// write response
echo 'granted';
}
}
}
?>
我想是存儲sid
在數據庫中的相關記錄(Accounts table
)。是什麼讓我困惑:
- 至於如果用戶成功登錄服務器後,複製一些頁面會使用相同的會話cookie我明白了嗎?我對嗎?除非瀏覽器關閉。
- 如何處理不同瀏覽器的情況?
- 我讀過,無論我需要使用會話,我都必須在頁面上調用
session_start()
。這不會給出sid
與登錄時寫入的不同嗎? - 說如果我不想重複,我的意思是用戶不應該多次訪問相同的資源(同時),哪種方式是最好的處理呢?
- 另外我明白,我需要使用某種標誌(可能在帳戶表中的字段)來說用戶是
active
,導致以其他方式,我將只存儲最後的sid
。或者更好的解決方案是在會話關閉後從數據庫中刪除用戶?
巨大的感謝!
出於好奇,你的'LDAPHandler.php'使用PHP的本地'ldap_bind()'? – Adi 2012-07-17 08:49:41
是的我正在使用本地ldap_bind();我還沒有後悔) – lexeme 2012-07-17 08:51:34
是否可以共享「LDAPHandler.php」的代碼? (特別是'ldap_bind()'附近的部分。在將個人信息排除在外之後,我一直在研究一些不好的練習案例,而且我非常好奇 – Adi 2012-07-17 08:53:07