簡體   English   中英

登錄后如何設置PHP重定向?

[英]How can I setup PHP Redirects after Login?

PHP的新功能在這里,嘗試弄清楚幾件事。 當用戶登錄系統時,我希望PHP查看組ID,然后運行檢查系統以查找匹配項。 匹配組ID后,它將把用戶重定向到相應的網頁。 我將如何用這段代碼來做到這一點?

這些是我表中的列:

Name, Email, Password, Group

在此先感謝您的幫助。 期待學習新的東西!

<?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);
?>

純粹作為示例使用此:

<?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");
    }


?>

假定這是一個清潔的if語句。 請查閱手冊並了解如何使其適應您的確切需求

由於您的問題中缺少信息,因此我不會更精確。 這是朝正確方向邁出的一步,但這一切都是猜測。 祝好運

暫無
暫無

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

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