首页 > 解决方案 > 安全原因 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:')

感谢你们 !

标签: phpsecurityurl

解决方案


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.


推荐阅读