好的,我坚持这一点。我尝试了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>";
}
?>
请帮助我...谢谢