0

好的,我坚持这一点。我尝试了isset功能,但没有任何反应......

登录后,用户将被重定向到特定页面。

如果主持人是她的 user_type,那么她将被重定向到 moderator.php 页面如果代理是她的 user_type,她将被重定向到 agent.php

我在这里有包含登录表单的 index.php

<form action="index.php" method=get>
    <?php
    session_start();
    if ($_SESSION["logging"] && $_SESSION["logged"]) {
        printme();
    }
    else {
        if (!$_SESSION["logging"]) {
            $_SESSION["logging"] = true;
            loginform();
        }
        else if ($_SESSION["logging"]) {
            $number_of_rows = checkpass();
            if ($number_of_rows == 1) {
                $_SESSION[user]   = $_GET[userlogin];
                $_SESSION[logged] = true;
                echo "<h1>You have logged in successfully</h1><br/>";
                echo "<a href='logout.php'>Logout</a> | <a href='users.php'>Click to proceed</a>";
            }
            else {
                loginform();
            }
        }
    }

    function loginform() {
        print ("<center><div id='login_header'><b><font face='Arial Black' color='black' size='4px'>Sign in to Minquep!</font></b></div></cen                   ter>");
        print("<br/><br/>");
        print ("<center><label>Username:</label><input type='text' name='userlogin' size='20'><br/><label>Password:</label><input type='                password' name='password' size='20'></center>");
        print "<br/><input type='submit' value='Submit' name='submit' class='submit'>";
    }

    function checkpass() {
        $dbHost = 'localhost';
        $dbUser = 'root';
        $dbPass = '';
        $dbname = 'minquep_test';
        $conn   = mysql_connect($dbHost, $dbUser, $dbPass); // Connection Code        mysql_select_db($dbname, $conn); // Connects to database      
        $sql    = "select * from users where login='$_GET[userlogin]' and password='$_GET[password]'";
        $result = mysql_query($sql, $conn) or die(mysql_error());
        $fetched = mysql_fetch_array($result);
        if ($fetched['user_type'] == "moderator") {
            echo '<script type="text/javascript">window.alert("You have logged in successfully!\n")</script>';
            print("<b><h1>hi mr.$_SESSION[user]</h1>");
            echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/moderator.php\">";
        }
        else if ($fetched['user_type'] == "agent") {
            echo '<script type="text/javascript">window.alert("You have logged in successfully!\n")</script>';
            echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/agent.php\">";
        }
    }

    function content() {
        print("<b><h1>hi mr.$_SESSION[user]</h1>");
        print "<br><h2>only a logged in user can see this</h2>";
    }

    function printme() {
        echo '<script type="text/javascript">window.alert("You have logged in successfully!\n")</script>';
    }

    ?>

</form>

从上面的代码中,这就是我如何根据用户类型将用户重定向到他们的特定页面。

if ($fetched['user_type'] == "moderator") {
    echo '<script type="text/javascript">window.alert("You have logged in successfully!\n")</script>';
    print("<b><h1>hi mr.$_SESSION[user]</h1>");
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/moderator.php\">";
}
else if ($fetched['user_type'] == "agent") {
    echo '<script type="text/javascript">window.alert("You have logged in successfully!\n")</script>';
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/agent.php\">";
}

现在在我的 moderator.php 中,我只调用了 moderator_include.php,我应该在其中打印登录用户的用户名和 user_type。

版主.php

<div id="wrapper">
    <div id="container">

        <div id="header">

            <?php include "moderator_header.php"; ?>

        </div>

它包括 moderator_header.php 是

<div class="logo">
    <a href="moderator.php"><img class="logo_img" src="../images/minquepLOGO.png"/></a>
</div>

<div id="title">
    <img src="../images/title.gif"/>

</div>
<br/>

<?php
    session_start();
    if ($_SESSION["logged"] = true) {


        print("<b><h1>hi mr. $_SESSION[user] . You are logged in as /*THE USER_TYPE GOES HERE */ </h1>");
    }
?>

我试图将用户名输出为

if (isset($_SESSION['logged'])){
    print("<b><h1>hi mr. $_SESSION[user] . You are logged in as /*THE USER_TYPE GOES HERE */ </h1>"); }

但是什么也没有发生...

关于如何输出用户的 user_type ......我不知道怎么做,因为它不是 index.php 中发生的会话的一部分

顺便说一句,我的 logout.php 是这样的

<?php
    session_start();
    if (session_destroy()) {
        print"<h2><B><blink>you have logged out successfully</B></blink></h2>";
        print "<h3><a href='index.php'>back to main page</a></h3>";
    }
?> 

请帮助我...谢谢

4

2 回答 2

0
print("<b><h1>hi mr " . $_SESSION['user'] . "You are logged in as" . $userType . "</h1>"); }

试试看 :)

编辑

将变量 $userType 编辑为它应该是什么...

于 2012-07-21T10:32:52.997 回答
0

有时 php 会变得有点棘手......要记住的一些事情

1)始终在任何输出之前启动会话,这意味着在您的代码顶部,在启动会话之前,甚至不应该有一个空格或空行。

2)当您有一个启动会话的文件并包含另一个文件时,您不必在包含的文件中再次启动它。

为了跟踪您的会话,在您想要的任何页面中添加以下代码:

<pre><?php print_r($_SESSION); ?></pre>

看看结果如何。

于 2012-07-21T10:35:29.803 回答