溫馨提示×

php中redirect參數(shù)中帶有id如何解決

PHP
小億
99
2024-05-28 12:56:07
欄目: 編程語言

在PHP中,如果redirect參數(shù)中帶有id,可以通過以下幾種方式解決:

  1. 將id參數(shù)拼接到重定向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參數(shù)存儲在session中,然后在重定向后獲?。?/li>
$id = $_GET['id'];
session_start();
$_SESSION['id'] = $id;
header("Location: http://example.com/page.php");
exit;

在頁面重定向后,可以通過$_SESSION[‘id’]獲取之前存儲的id參數(shù)。

0