温馨提示×

php中redirect参数中带有id如何解决

PHP
小亿
82
2024-05-28 12:56:07
栏目: 编程语言

在PHP中,如果redirect参数中带有id,可以通过以下几种方式解决:

  1. 将id参数拼接到重定向URL中:
$id = $_GET['id'];
header("Location: http://example.com/page.php?id=$id");
exit;
  1. 使用urlencode对id进行编码:
$id = $_GET['id'];
$id = urlencode($id);
header("Location: http://example.com/page.php?id=$id");
exit;
  1. 将id参数存储在session中,然后在重定向后获取:
$id = $_GET['id'];
session_start();
$_SESSION['id'] = $id;
header("Location: http://example.com/page.php");
exit;

在页面重定向后,可以通过$_SESSION[‘id’]获取之前存储的id参数。

0