用户登录后,将登录按钮更改为注销按钮

时间:2015-07-04 18:11:49

标签: javascript php jquery html login

我已阅读这些链接:

我有一个问题,有点具体。我有一个minimallogin文件夹,其中包含所有注册和登录PHP代码。在此文件夹中,我有index.php,其中包含以下代码:

<?php
// checking for minimum PHP version
if (version_compare(PHP_VERSION, '5.3.7', '<')) {
    exit("Sorry, Simple PHP Login 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 configs / constants for the database connection
require_once("config/db.php");

// load the login class
require_once("classes/Login.php");

$login = new Login();

// ... ask if we are logged in here:
if ($login->isUserLoggedIn() == true) {

    //after logged in


} else {

    //after logged out
}
?>

我尝试了以下两件事,但要么被困在某处,要么无法让它发挥作用:

1)第一种方法(使用Javascript)我已将ID registerloginarea(以HTML格式)提供给我想要使用我的注销链接更改登录按钮的区域。我尝试过很多东西。我只是学习Javascript,因此我尝试编写这样的函数:

function loggedin(){
    document.getElementById("registerloginarea").innerHTML="logged in";
}

但我真的不知道如何将这个功能实现到我的index.php(登录后的部分)。

注意:另外我不想输出“已登录”。我希望在用户登录后输出为“Hey,[name] .Logout”代替登录按钮,代码为:

Hey, $_SESSION['user_name']
<a href="index.php?logout">Logout</a>"

2)或者,我也这样做了:

<ul id="registerloginarea" class="nav navbar-nav navbar-right navbar-btn">
                <?php
                include("/minimallogin/index.php");

                $login = new Login();

                // ... ask if we are logged in here:
                if ($login->isUserLoggedIn() == true) {
                    // the user is logged in. you can do whatever you want here.
                    // for demonstration purposes, we simply show the "you are logged in" view.
                    echo $_SESSION['user_name'];
                    echo "<a href=\"index.php?logout\">Logout</a>";



                } else {
                    // the user is not logged in. you can do whatever you want here.
                    // for demonstration purposes, we simply show the "you are not logged in" view.
                    include("/var/www/html/C-CubeClub/includes/registerloginarea.php");
                }
                ?>
           </ul>

$login...之前的半部分包含在minimallogin/index.php中。 但是当我登录时,它会解析minimallogin/index.php(因为我已将<form action="minimallogin/index.php">包含在我的表单中。 你怎么建议我把这个东西搞定。它可能有一个非常简单的答案,但请原谅我。

0 个答案:

没有答案