簡體   English   中英

PHP代碼未重定向

[英]PHP code not Re-directing

這段代碼有什么問題... ??? 它沒有重定向到另一頁,而是停留在login.php頁(空白頁)上。數據庫都是正確的。有人可以在此代碼上為我提供幫助。非常感謝您的幫助...

<?
require_once('include/config.php');
require_once('include/functions.php');

session_start();

session_destroy();

$message="";


$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$md5_password=md5($_POST['password']); // Encrypt password with md5() function.



mysql_select_db("$db", $con);


$result=mysql_query("select * from staff where stf_username='$username' and    stf_password='$md5_password'");
$sql =mysql_query("select stf_level from staff where stf_username='$username'");


if(mysql_num_rows($result)!='0'){ // If match.
session_register("username");
while($row = mysql_fetch_array($sql))
{
//echo $row['level'] . " ";
if($row['stf_level'] == 1){
header("location:admin/index.php");
}
elseif($row['stf_level'] == 2){
header("location:cashier/index.php");
 }
 elseif($row['stf_level'] == 3){
 header("location:waiter/index.php");
 }
 elseif($row['stf_level'] == 4){
 header("location:kitchen/index.php");
 }
 }

//header("location:main.php"); // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}

} // End Login authorize check.
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />

<meta name="description" content="Description" />
<meta name="keywords" content="Keywords" />

<meta name="author" content="Aafrin" />


<title>iCafe Login</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/keyboard.css" />
<script type="text/javascript"      src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript" src="js/keyboard.js"></script> 

</head>

<body>
<div id="wrapper">

<div id="loginPanel">
<img class="image" alt="" src="images/logo.png" width="220" height="120" />
<div id="error"><? echo $message; ?></div>

<form id="form" name="form" method="post" action="<? echo $PHP_SELF; ?>">

    <label>Username :</label>
        <input type="text" name="username" class="keyboardInput" />

    <label>Password :</label>
        <input type="password" name="password" class="keyboardInput"  />

    <input name="Login" type="submit" id="Login" value="Login" class="submit" />
    <!--    
    <input type="submit" value="Submit" name="submit" class="submit"  />
    -->

</form>

<div id="footer">
XYZ © 2012 - All Rights Reserver | Powered By <a     href="http://www.facebook.com/kesavans">Kesavan</a>
</div>

</div>
<!--
<div id="details">
<p>Login Details</p>
Admin : admin
<br />
Waiter : waiter
<br />
Kitchen : kitchen
<br />
Cashier : cash
</div>
-->
</body>

</html>

我認為您應該在:之后放置空格,就像

header("location: cashier/index.php");

嘗試@header("")可能是您出錯了。 為什么不將所有位置保存在變量中,然后將變量傳遞給標頭函數?

if($x=1){$loc="admin/index.php"}
if($x=2){$loc="staff/index.php"}
if($x=3){$loc="manager/index.php"}
@header('location:$loc')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM