如果用户帐户未激活,则重定向到不同页面

发布于 2024-11-15 23:57:42 字数 1077 浏览 5 评论 0原文

一段代码

$LoginRS__query=sprintf("SELECT user_handle, user_password FROM users_entity WHERE user_handle=%s AND user_password=%s AND activation_status='Active'",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $f12_database_connect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";


    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['logged_in']="True";
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

数据库查询 activation_status="Active" 的用户。该字段具有两个值之一:“Pending”“Active”。如果状态为“待处理”,我想发送到另一个页面。该页面适用于尚未激活帐户的用户。如何获取结果并将其分配给变量?或者有更好的方法吗?

A snip of code

$LoginRS__query=sprintf("SELECT user_handle, user_password FROM users_entity WHERE user_handle=%s AND user_password=%s AND activation_status='Active'",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $f12_database_connect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";


    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['logged_in']="True";
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

The database queries users that are activation_status="Active". That field has either of the two values which are "Pending" or "Active". I want to send to another page if the status is "Pending". The page would be for users that haven't activated their account. How do grab that result and assign it to a variable? Or is there a better approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只需选择数据而不参考activation_status并使用if语句检查它。

编辑:

您可能正在寻找的代码:

$LoginRS__query=sprintf("SELECT user_handle, user_password, activation_status FROM users_entity WHERE user_handle=%s AND user_password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $f12_database_connect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    // Make sure user is activated.
    $row = mysql_fetch_Array($LoginRS);
    if ($row['activation_status'] === 'Pending') {
      header("Location: some-other-page");
    }

    $loginStrGroup = "";


    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['logged_in']="True";
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

Just select the data without referring to the activation_status and check it with an if statement.

EDIT:

The code you are probably looking for:

$LoginRS__query=sprintf("SELECT user_handle, user_password, activation_status FROM users_entity WHERE user_handle=%s AND user_password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $f12_database_connect) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    // Make sure user is activated.
    $row = mysql_fetch_Array($LoginRS);
    if ($row['activation_status'] === 'Pending') {
      header("Location: some-other-page");
    }

    $loginStrGroup = "";


    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['logged_in']="True";
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
捎一片雪花 2024-11-22 23:57:42

这是解决方案和正确的编码...

<?php
$LoginRS_StrQuery   =   'SELECT user_handle, user_password, activation_status FROM users_entity '.
                        "WHERE user_handle=%s AND user_password=%s LIMIT 0,1";
$LoginRS__query     =   sprintf($LoginRS_StrQuery, GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS            =   mysql_query($LoginRS__query, $f12_database_connect);
if(is_resource($LoginRS) && mysql_num_rows($LoginRS) > 0){
    $loginStrGroup  =   '';

    //declare two session variables and assign them
    $_SESSION['MM_Username']    =   $loginUsername;
    $_SESSION['logged_in']      =   'True';
    $_SESSION['MM_UserGroup']   =   $loginStrGroup;

    $LoggedUser     =   mysql_fetch_assoc($LoginRS);
    if($LoggedUser['activation_status'] === 'Pending'){
        // redirect him/her to wherever you want
    } elseif(isset($_SESSION['PrevUrl']) && true){
        $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
        exit;
    } else{
        header("Location: " . $MM_redirectLoginSuccess );
        exit;
    }
} else{
    header("Location: ". $MM_redirectLoginFailed );
    exit;
}
?>

This is the solution and proper coding...

<?php
$LoginRS_StrQuery   =   'SELECT user_handle, user_password, activation_status FROM users_entity '.
                        "WHERE user_handle=%s AND user_password=%s LIMIT 0,1";
$LoginRS__query     =   sprintf($LoginRS_StrQuery, GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS            =   mysql_query($LoginRS__query, $f12_database_connect);
if(is_resource($LoginRS) && mysql_num_rows($LoginRS) > 0){
    $loginStrGroup  =   '';

    //declare two session variables and assign them
    $_SESSION['MM_Username']    =   $loginUsername;
    $_SESSION['logged_in']      =   'True';
    $_SESSION['MM_UserGroup']   =   $loginStrGroup;

    $LoggedUser     =   mysql_fetch_assoc($LoginRS);
    if($LoggedUser['activation_status'] === 'Pending'){
        // redirect him/her to wherever you want
    } elseif(isset($_SESSION['PrevUrl']) && true){
        $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
        exit;
    } else{
        header("Location: " . $MM_redirectLoginSuccess );
        exit;
    }
} else{
    header("Location: ". $MM_redirectLoginFailed );
    exit;
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文