dongnao2582 2016-10-17 16:56
浏览 7
已采纳

如何在登录后设置PHP重定向?

New to PHP Here, trying to figure out a couple of things. When users log into the system, I would like for the PHP to look at the Group ID and then run through a system of checks to find a match. Once the Group ID is matched, it will then redirect users to the appropriate webpage. How would I go about doing this with this piece of code?

These are the columns in my table:

Name, Email, Password, Group

Thanks in advance for your help. Looking forward to learning something new!

<?php
$con=mysqli_connect("localhost", "username", "password", "dbName");
//"localhost", "userName" is username; "Password" is password; "dbName" is DB_Name;
if (mysqli_connect_errno($con))
{
    echo "MySql Error: " . mysqli_connect_error();
    }

$query=mysqli_query($con,"SELECT * FROM user_reg WHERE UserName='$_POST[UserName]' && Password='$_POST[Password]'");
$count=mysqli_num_rows($query);
$row=mysqli_fetch_array($query);

if ($count==1)
{
    session_start();
    $_SESSION['UserName'] = $_POST['UserName'];
    $_SESSION['Password'] = $_POST['Password'];
    header("location: redirect.html");
    }
else
{
    echo "Invalid username or password";
    }   

mysqli_close($con);
?>
  • 写回答

1条回答 默认 最新

  • douxi1968 2016-10-17 17:05
    关注

    Purely as an example use this:

    <?php
        /*
            GroupID 1 = Standard User
            GroupID 2 = Special User
            GroupID 3 = Power User
    
        */
    
        $GroupID = $_POST['GroupID']; // Assume 1 
    
    
        switch($GroupID){
            case 1: 
            // If GroupID = 1 Redirect to correct page
                header("Location: StandardPage.html");
            case 2:
            // If GroupID = 2 Redirect to correct page
                header("Location: SpecialUser.html");
            case 3:
            // If GroupID = 3 Redirect to correct page
                header("Location: Poweruser.html");
            default:
            // If GroupID does not match set user groups redirect to error page
                header("Location: Error.php");
        }
    
    
    ?>
    

    Assume this as a cleaner if statement. Please Consult the manual and learn how to adapt this to your exact needs

    as the lack of information in your question, I will not be more precise. This is a step in the right direction, but all this is of guess work. Good Luck

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大