php - 安全原因 PHP
问题描述
登录成功后,用户会跳转到他对应的页面。所以我用一个header('Location: URL?id=$id)
我该怎么做才能使 ID 隐藏在 url 中。这样用户就不能更改 URL 上的 ID?例如,我以普通用户身份登录,我的 id 来自数据库 63,所以 un url 是 display, page.php?id=63
现在,当用户将 id 更改为 64 时,他将从 id 为 64 的用户那里获取页面。出于安全原因,我将在此之前更改它以使站点在线。
如何通过向用户发送一个header('Location:')
感谢你们 !
解决方案
Instead of stroing the id in the URL, you can store it in a session variable.
You can start a session by using the following:
session_start();
And you can assign session variables using:
$id = x; #id taken from database. change x to the database variable
$_SESSION["id"] = $id;
Replace 123 with the database user id variable.
Also add session_start()
to pages where you would want to use the $_SESSION
variable.
推荐阅读
- winapi - Windows 7 上的 GDI+ 透明位图
- node.js - RTSP 流因错误退出”:连接超时
- r - 子集列表中的问题
- python - Python seaborn plot 将数据名称显示为ㅁㅁㅁㅁ。我怎样才能解决这个问题?
- ms-access - 在 MS Access 中使用 SQL 计算多样性指数
- regex - 正则表达式将所有单词截断为最大单词长度?
- javascript - React Native Map View 初始渲染
- python - 如何将 L1 正则化添加到 PyTorch NN 模型?
- vba - 登录后的Http post请求
- c# - C# 数学库(System.Numerics 与 Math.NET)