好吧,我堅持這一點。我嘗試了isset功能,但沒有任何反應...登錄後會話輸出用戶名和用戶類型PHP
登錄後,用戶將被重定向到特定頁面。
如果主持人是她USER_TYPE她就會被重定向如果代理的是她,她USER_TYPE就會被重定向到agent.php
到moderator.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>
從上面的代碼,這是我如何根據用戶的user_type重定向用戶到他們的特定頁面。
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 裏面我只是打電話,我應該打印登錄用戶的用戶名和USER_TYPE的moderator_include.php。
moderator.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>";
}
?>
請幫我...謝謝
正確縮小代碼將使您(以及我們)更好地閱讀代碼。另外,請給我們一個簡短的相關代碼片段,而不是您的整個應用程序。 – 2012-07-21 11:20:54
好的,謝謝... – 2012-07-21 11:27:23