当前位置:网站首页>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>";
}
?>边栏推荐
- Oracle update and delete data
- Mujoco and mujoco_ Install libxcursor.so 1:NO such dictionary
- 数据湖:分布式开源处理引擎Spark
- Review key points and data sorting of information metrology in the second semester of 2022 (teacher zhaorongying of Wuhan University)
- Vscode one click compilation and debugging
- Makefile(make)常见规则(二)
- pulsar起client客户端时(client,producer,consumer)各个配置
- Ethernet of network
- 【Express连接MySQL数据库】
- IOS interview preparation - Objective-C
猜你喜欢

(heap sort) heap sort is super detailed, I don't believe you can't (C language code implementation)

UE plays video in scene or UMG

On quotation

如何避免示波器电流探头损坏

Update learning materials daily

网络之以太网

EMI interference troubleshooting with near-field probe and current probe

使用近场探头和电流探头进行EMI干扰排查

Review key points and data sorting of information metrology in the second semester of 2022 (teacher zhaorongying of Wuhan University)

Implementation of flutter gesture monitoring and Sketchpad
随机推荐
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
Dasctf2022.07 empowerment competition
How to avoid damage of oscilloscope current probe
Log configuration logback
[C language] PTA 7-91 output leap year
Pyqt5 learning pit encounter and pit drainage (1) unable to open designer.exe
2022杭电多校联赛第四场 题解
STL source code analysis (Hou Jie) notes -- Classification and testing of stl containers
在线教育的推荐系统
I++ and ++i details
oracle 更新和删除数据
Oracle 插入数据
Makefile+make Basics
Mysql:The user specified as a definer (‘root‘@‘%‘) does not exist 的解决办法
Webrtc realizes simple audio and video call function
Mpc5744p introduction and opensda firmware update
Auto.js脚本开发环境搭建
LeetCode(剑指 Offer)- 53 - I. 在排序数组中查找数字 I
Vscode one click compilation and debugging
VScode配置makefile编译