PHPBB Ajax外部登录

时间:2016-02-11 02:20:18

标签: php jquery ajax forum phpbb

我在尝试获取PHPBB的外部登录以使用AJAX时遇到了一些问题。我不确定我在这里失踪了什么,所以这就是我得到的:

HTML:

<div id="dialogin" class="dialoghide" title="Loading...">
    <form id="loginformadj" name="loginformadj" action="forum/ucp.php?mode=login" method="post" data-ajax="true" data-refresh="false">
        <h3><a id="dialoglogin" href="forum/ucp.php?mode=login" data-ajax="true">Login</a>&nbsp; &bull; &nbsp;
        <a id="dialogregister" href="forum/ucp.php?mode=register" data-ajax="true">Register</a></h3>
        <fieldset id="userinfo">
            <label for="username">Username:</label>&nbsp;
            <input type="text" name="username" id="username" size="10" title="Username" />
            <label for="password">Password:</label>&nbsp;
            <input type="password" name="password" id="password" size="10" title="Password" />
            <label for="autologin">Log me on automatically<input type="checkbox" name="autologin" id="autologin" /></label>
        </fieldset>
        <fieldset class="submit-buttons">
            <input type="submit" name="login" value="Login" />
            <input type="hidden" name="redirect" value="./index.php" />
        </fieldset>
    </form>
</div>

JS包含在页面上:

$(document).ready(function() {
    // handle the login form through ajax for phpbb
    $('#loginformadj').on('submit', 'form', function(event) {
        event.preventDefault();

        var url= $(this).attr('action');
        alert(url);
        $.ajax({
            url: url,
            type: 'POST',
            dataType: 'HTML',
            data: new FormData(this),
            processData: false,
            contentType: false,
            success: function (data, status) {
                alert(data);
            },
            error: function (xhr, desc, err) {
                console.log('error');
            }
        });
    });
});

这是在我使用phpbb会话和其他功能的另一个文件的页面顶部需要的:

<?php
/*
 * BEGIN PHPBB STANDARD PAGE SETUP
 */
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$website_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);
//include($phpbb_root_path . 'includes/functions.' . $phpEx);
include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
/*
 * END PHPBB STANDARD PAGE SETUP
 */
?>

将表单拉入jquery对话框。它确实登录我,然后立即将我重定向到./forum的论坛索引,而不是使用ajax并发送警报。我没有收到任何我设置的警报或其他任何警报。我已经尝试了所有我能想到的东西。 :/

要添加,我有用户名,用户头像,并且还可以在我的外部页面上注销所有内容。只是无法登录才能正常工作。

1 个答案:

答案 0 :(得分:0)

这个问题,至少在最初阶段,是我在调查论坛提交检查jquery是否错误。

$(document).ready(function() {
// handle the login form through ajax for phpbb
$(document).on('submit', '#login', function(event) {
    event.preventDefault();

    var url= $(this).attr('action');
    alert(url);
    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'HTML',
        data: new FormData(this),
        processData: false,
        contentType: false,
        success: function (data, status) {
            alert(data);
        },
        error: function (xhr, desc, err) {
            console.log('error');
        }
    });
});
});

我还读到你需要在隐藏字段中使用$ user-&gt;数据调用sid。我把它包括在表格中,并没有检查它是否重要。