当前位置:网站首页>Redirect to previous page after login? PHP - Redirecting to previous page after login? PHP
Redirect to previous page after login? PHP - Redirecting to previous page after login? PHP
2022-06-25 07:12:00 【Technology feast】
problem :
I've been searching for a solution but it's seem I can't get it right, no matter what I try. I've been looking for a solution , But whatever I try , I can't seem to solve the problem .
After successful login, the user should be redirected to the page he came from, let's say he's been browsing a post and wants to log in so he can leave a comment, so he should be redirected to the post he was browsing. After successful login , The user should be redirected to the page he came from , Suppose he has been browsing a post and wants to log in so that he can comment , So he should be redirected to the post he is browsing .So here is what I have: So this is what I have :
login.php shows the login form:login.php Show login form :
<form method="post" action="login-check.php">... //input for username and password</form>The login-check.php checks if the username and pass are entered, does the user exist, or if he's already logged in, and a p parameter is sent to login.php:login-check.php Check whether the user name and password are entered , Does the user exist , Or whether he has logged in , And to login.php Send a p Parameters :
<?phpsession_start();if((empty($username) OR empty($password) AND !isset($_SESSION['id_login']))) { header("Location:login.php?p=1"); exit();}elseif (!user_exists($username,$password) AND !isset($_SESSION['id_login'])) { header("Location:login.php?p=2"); exit();}elseif(isset($_SESSION['id_login'])) { header("Location:login.php?p=3"); exit();}?>then parameter p is sent back to login.php and displays the according message: And then the parameters p Be sent back to login.php And display the corresponding message :
<?phpif(isset($_GET['p'])) { $p = $_GET["p"]; if($p=="1") echo "<p class=\"red\">You didn't fill the form.</p><br></br>"; if($p=="2") echo "<p class=\"red\">User exists.</p><br></br>"; if($p=="3") header("Location: index.php");}?>BUT, instead of going to index.php after successful login, it should go to the page the user has previously been. however , After successful login , Not to index.php, Instead, go to the page the user has visited before .I've tried in different ways but ether it doesn't work at all or it returns to login.php. I tried different ways , But the ether doesn't work at all , Or it returns to login.php.It doesn't need to be super safe, because I'm doing this for a school project. It doesn't need super security , Because I am doing this for the school project .
ALSO, I consider myself pretty novice, so please have patience :D in addition , I think I am a novice , So please wait patiently :D
Solution :
Reference resources : https://stackoom.com/en/question/ywDU边栏推荐
- 【一起上水硕系列】Day 4
- Unity get resource path
- The process of making wooden barrels with 3DMAX software: a three-step process
- 分布式锁中的王者方案 - Redisson
- 【他字字不提爱,却句句都是爱】
- Non-contact infrared temperature measurement system for human body based on single chip microcomputer
- [Shangshui Shuo series] day 5
- Drawing shp files using OpenGL
- Jameswebb Space Telescope goes into operation to help study interstellar objects
- Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
猜你喜欢

网络是怎样连接的?

分布式锁中的王者方案 - Redisson

使用OpenGL绘制shp文件

Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)

Are you still doing the dishes yourself? Teach you how to make dishwasher controller with single chip microcomputer

Flask 的入门级使用
![[ros2] Why use ros2? Introduction to ros2 system characteristics](/img/d8/8906e01f9715328f3a05a51ab82fb1.png)
[ros2] Why use ros2? Introduction to ros2 system characteristics

赚够钱回老家吗

Pratique de gestion hiérarchique basée sur kubesphere

Atomic alpha development board -- SD card and EMMC burning tool
随机推荐
keil debug查看变量提示not in scope
How do I know if mysqlnd is an active driver- How to know if MySQLnd is the active driver?
有了 MySQL 为什么要用 NoSQL?
[Shangshui Shuo series] day 4
3dmax软件的制作木桶过程:三步流程
【xxl-job】池塘水绿风微暖,记得玉真初见面
ES 终于可以搜到”悟空哥“了!
How to get the difference between two dates rounded to hours
TorchServe避坑指南
CTFHub-Web-信息泄露-目錄遍曆
2022 biological fermentation Exhibition (Jinan), which is a must read before the exhibition. The most comprehensive exhibition strategy will take you around the "fermentation circle"
Usage of STL map
Too beautiful promise because too young
[learn shell programming easily]-5. Plan tasks
【工具分享】一款颜值与技能并重的软件
Shell command learning
Atomic alpha development board -- SD card and EMMC burning tool
Your local changes to the following files would be overwritten by merge: . vs/slnx. sqlite
Modify the default log level
聚类和分类的最基本区别。