0

这是我的 login.php

 <form action="index.php" method=get>


      <?php
     error_reporting(E_ALL & ~E_NOTICE);
      ?>


    <?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>';
    echo "Welcome {$_SESSION['user']}";
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/moderator.php\">";
                    }
    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>

现在,每当用户登录...如果他的 user_type 是“主持人”,他将被重定向到 moderator.php

如果他的 user_type 是“agent”,他将被重定向到 agent.php

我想要发生的是在用户将被重定向到的页面中输出用户名和用户类型。

这就是我的 agent.php 和 moderator.php

<?php session_start();

    echo "Welcome {$_SESSION['user']} . And You are Logged in as /*USER TYPE SHOULD BE DISPLAYED HERE */ ";

 ?>

我收到此错误:

错误截图

4

2 回答 2

0

在你的agent.php中试试这个

<?php session_start();

    if (array_key_exists('user', $_SESSION) && !empty($_SESSION['user'])) {

        echo "Welcome {$_SESSION['user']} . And You are Logged in as /*USER TYPE SHOULD BE DISPLAYED HERE */ ";

    } else {

        echo "Welcome stranger";
    }

 ?>
于 2012-07-21T12:33:27.497 回答
0

由于您有不同的 PHP 文件,moderator.php并且agent.php,您可以简单地使用;

在 moderator.php 中,

echo "Welcome {$_SESSION['user']} . And You are Logged in as MODERATOR";

在agent.php中,

echo "Welcome {$_SESSION['user']} . And You are Logged in as AGENT";

没有大任务。。

于 2012-07-21T12:33:34.080 回答