简体   繁体   中英

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

I'm building a login system. My database looks like this<\/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.
So user yyy would be send to lets say TG111.php
And user uuu would be send to lets say TG112.php

TG111.php looks like this<\/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($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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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