简体   繁体   English

"如何让特定用户访问 PHP 中的特定网站?"

[英]How do I give specific users access to specific websites in PHP?

I'm building a login system.我正在构建一个登录系统。 My database looks like this<\/a>我的数据库看起来像这样<\/a>
Lets say, after loggin in, the code recognizes who is currently logged in and sends them to a specific website, based on the content in their KURS field.比方说,登录后,代码会根据其 KURS 字段中的内容识别当前登录的用户并将其发送到特定网站。
So user yyy would be send to lets say TG111.php所以用户 yyy 将被发送到 TG111.php
And user uuu would be send to lets say TG112.php用户 uuu 将被发送到 TG112.php

TG111.php looks like this<\/strong> TG111.php 看起来像这样<\/strong>

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

I'm not sure what you're looking for?我不确定你在找什么? but you can try to debug it to see what the problem, you can try using this in your if statement但是您可以尝试调试它以查看问题所在,您可以尝试在 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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM