简体   繁体   English

如何使页面仅在登录后可访问

[英]How to make an page only accessible when logged in

How to make an page only accessible when logged in, in PHP? 如何使页面仅在使用PHP登录后才能访问?

I want you when you click on the background to defend two buttons with Login And Register and you can only access these two buttons after you log in. 当您单击背景以使用“登录并注册”保护两个按钮时,我想要您,并且您只能在登录后访问这两个按钮。

<?php
session_start();
include_once 'dbconnect.php';

?>
<!DOCTYPE html>

<HTML>
<head>
    <title>NCS pagina principala</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport" >
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" >

</head>
<body>

                <?php if (isset($_SESSION['usr_id'])) { ?>
                <FONT size="4%" color="#66ffff" FACE="cursive">Esti conectat cu:</FONT><i><FONT size="5" color="#66ff66"> <?php echo $_SESSION['usr_name']; ?></FONT></i>

                <link rel="stylesheet" href="styles/buttonstyle.css">
                                 <a class="button" href="logout.php">Delogheaza-te</a>

                <?php } else { ?>
 <link rel="stylesheet" href="styles/buttonstyle.css">
<a class="button" href="login.php">Logheaza-te</a>
<a class="button" href="form.html">Cerere cont</a>
                <?php } ?>

<head>

<a class="button" href="blacklist.php">BlackList</a>
<CENTER>


<BODY STYLE = "BACKGROUND: url(https://cdn.discordapp.com/attachments/389773843813629972/389781868247253002/thumb-1920-553248.jpg); BACKGROUND-SIZE:130%"></BODY>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

</HTML>

try this (after session_start(); ): 试试这个(在session_start();之后):
if (!isset($_SESSION['usr_id'])) header("Location:logout.php");


and logout.php must be 和logout.php必须是

<?php 
session_start();
session_destroy();
header("Location:login.php");
?>

then, in login.php you write your login code 然后,在login.php中编写您的登录代码

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

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