【问题标题】:How do I give specific users access to specific websites in PHP?如何让特定用户访问 PHP 中的特定网站?
【发布时间】:2022-02-07 12:31:15
【问题描述】:

我正在构建一个登录系统。我的数据库看起来像 this
假设登录后,代码会根据其 KURS 字段中的内容识别当前登录的用户并将其发送到特定网站。
所以用户 yyy 将被发送到 TG111.php
用户 uuu 将被发送到 TG112.php

TG111.php 看起来像这样

<?php
session_start();

    $sess = $_SESSION['KURS'];

    if ($sess !== 'TG111') {
      if ($sess !== 'TG112') {
        if ($sess !== 'TG113') {
          header("Location: index.php");
          exit();
        }
        else {
          header("Location: TG113.php");
          exit();
        }
      }
      else {
        header("Location: TG112.php");
        exit();
      }
    }
    else {
      header('Location: TG111.php');
      exit();
    }

?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Hello</title>
  </head>
  <body>

    <a href="logout.php">Abmelden</a>
  </body>
</html>


但这不起作用...

【问题讨论】:

  • 尝试设置$_SESSION['KURS']

标签: php session


【解决方案1】:

我不确定您在寻找什么?但是您可以尝试调试它以查看问题所在,您可以尝试在 if 语句中使用它

if($sess == 'TG111') {
    header('Location: TG111.php');
    exit();
} elseif ($sess == 'TG112') {
    header("Location: TG112.php");
    exit();
} elseif ($sess == 'TG113') {
    header("Location: TG113.php");
    exit();
} else {
    header("Location: index.php");
    exit();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    相关资源
    最近更新 更多