這是我的login.php顯示登錄後的用戶名和用戶類型。 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.php
我想要發生的是在用戶將被重定向到的頁面中輸出用戶名和usertype。
這是我在agent.php已經有了和moderator.php
<?php session_start();
echo "Welcome {$_SESSION['user']} . And You are Logged in as /*USER TYPE SHOULD BE DISPLAYED HERE */ ";
?>
我得到這個錯誤:
我甚至不能指向特定的問題,因爲所有的代碼is sooooooooo wrong – zerkms 2012-07-21 12:27:49
檢查這一行'$ _SESSION [user] = $ _ GET [userlogin];'你沒有引用'user'常量 – codingbiz 2012-07-21 12:27:57
@codingbiz:它不會改變任何東西(我並不是爭辯說報價應該放在那裏,但它不會改變該行的行爲) – zerkms 2012-07-21 12:28:51