我需要一些重定向的帮助。我有一段代码,希望将用户重定向到特定的页面。包含用户名和密码的表还包含第三部分数据,即组织名称。每个组织都有自己的页面。--我在第17行中增加了一家公司的名称,但我一直在下面得到回音。任何帮助都会很好。
$dbc = dbConnect();
$username = "exampleuser";
$sql = "SELECT 'password' from users where 'username' = '$username';";
$result = mysql_query($sql, $dbc); //run the query
if ($result)
{
$row = mysql_fetch_assoc($result);
$password = $row['password'];
// echo '<h2>Result Found '.$password.'</h2>'.PHP_EOL;
$myPassword = $_POST['password'];
$row = mysql_fetch_assoc($result);
//$password = $row['password'];
//match passwords
if($myPassword == $password){
//Decide where to send user depending on company column:
$privilege = $row['company'];
if($privilege == "companyname"){
header( 'Location: admin1.php' );
}
if($privilege == "user"){
header( 'Location: user.php' );
}
if($privilege == "other"){
header( 'Location: other.php' );
}
exit; //This tells php to stop executing as soon as we redirect
}else{
echo "Wrong username/password, try again";
}
}发布于 2013-10-06 18:45:38
基本上,php中的任何重定向都是使用header函数完成的。
例如,这样的电话:
header( 'Location: http://google.com' );将用户重定向到google.com
了解这段信息后,我们将根据从数据库获取的信息,使用该信息重定向用户,
假设我们从名为myPassword的POST变量中输入用户的密码
$myPassword = $_POST['password'];
$row = mysql_fetch_assoc($result);
$password = $row['password'];
//match passwords
if($myPassword == $password){
//Decide where to send user depending on privilege column:
$privilege = $row['privilege'];
if($privilege == "admin"){
header( 'Location: admin.php' );
}
if($privilege == "user"){
header( 'Location: user.php' );
}
if($privilege == "other"){
header( 'Location: other.php' );
}
exit; //This tells php to stop executing as soon as we redirect
}else{
echo "Wrong username/password, try again";
}
}
else
{
echo '<h2>No user found, or Error: '.mysql_error().' </h2>';
}https://stackoverflow.com/questions/19212402
复制相似问题