当前位置:网站首页>PHP determines whether the user has logged in. If logged in, the home page will be displayed. If not, enter the login page or registration page
PHP determines whether the user has logged in. If logged in, the home page will be displayed. If not, enter the login page or registration page
2022-07-29 04:45:00 【The breeze also misses the rain】
login.php
I use it here session Instead of cookie, Think the same ,session The code is simpler to operate , Easier to demonstrate .
<?php
$user = ... ...; // Here is the data about users queried by the database
if ($user != null || $user != "") {
// Here are the settings cookie, It needs to be opened before use cookie, I used it here session, Think the same ,session concise , Easy to demonstrate .
//setcookie("user", $user['user_id'], time() + 1 * 24 * 3600);
// Turn on session
session_start();
// In the data
$_SESSION['user'] = $user['user_id'];
// After saving, jump to the home page
echo "<script>window.location.href='index.php'</script>";
} else {
echo "<script>alert(' Wrong account or password !')</script>";
}
?>index.php
This is the home page , Judgment is needed , If you pass session User information is found , Then the corresponding content is displayed .
?php
// Injected into database operations PHP file ( It is easier to operate the database ), I have previously posted a blog about database static tools ,
// Blog links :https://blog.csdn.net/qfxl0724/article/details/125847351
include_once "DBHelper.php";
// Use session To determine whether the user is logged in
session_start();
// Use variables to receive session Information of users in
$user = $_SESSION['user'];
if ($user == null || $user == '') {
echo "<a class='login' href='login.php'> Sign in </a>";
echo "<a class='enroll' href='enroll.php'> register </a>";
} else {
echo "<a class='myspace' href='user/index.php'> My home page </a>";
}
?>边栏推荐
- Idea small settings
- 读懂 互联网巨头 【中台之战】 以及 中台 发展思维
- IOS interview preparation - other articles
- 学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置
- Take you to understand JS array
- Log configuration logback
- File operation (Advanced C language)
- Software test interview questions (4)
- Several simple and difficult OJ problems with sequential force deduction
- Deep analysis of data storage in memory (Advanced C language)
猜你喜欢
![Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan](/img/6c/f24407133663c0e19d6fa05c611341.png)
Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan

WebRTC实现简单音视频通话功能

Star a pathfinding in LAYA

Google browser opens the web page and out of memory appears

GCC Basics

Unity基础(3)—— unity中的各种坐标系

Make a virtual human with zego avatar | virtual anchor live broadcast solution

MySQL - 深入解析MySQL索引数据结构

UE plays video in scene or UMG

spinning up安装完使用教程测试是否成功,出现Library“GLU“ not found和‘from pyglet.gl import *错误解决办法
随机推荐
GCC Basics
Detailed comparison of break and continue functions
What is the difference between field, variable and property
Nail dialog text converted to pictures cannot be copied and pasted on the document
正确的用户拖拽方式
i++与++i详解
Recyclerview switches the focus up and down through the dpad key. When switching to the control outside the interface, the focus will jump left and right
Reveal installation configuration debugging
VScode配置makefile编译
TypeError: Cannot read properties of undefined (reading ‘then‘)
UE plays video in scene or UMG
数据湖:分布式开源处理引擎Spark
学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置
[C language] PTA 7-52 finding the sum of the first n terms of a simple interleaved sequence
Recommendation system of online education
Reveal安装配置调试
MySQL - 聚簇索引和辅助索引
Webrtc realizes simple audio and video call function
Coding questions encountered in the interview
RecyclerView通过DPAD按键上下切换焦点 切换到界面外的控件时焦点会左右乱跳